Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

two module-info.java in one package

I want to make work the project with two module inside one package. There is package com.test which include test1 and test2. This code is note compile because:

Error:Multiple module-info files in module 'Java9Test'

What is not correct?

test1 contains module-info.java

module com.test.test1 {} 

and Client.java

package com.test.test1;

import com.test.test2.Provider;

public Client {
    public static void main(String[] args) {
        Provider provider = new Provider();
        System.out.printf(provider.getString(), "TestA");
    }
}

and package test2 which contains

module-info.java

module com.test.test2 {}

and Provider.java

package com.test.test2;

public class Provider {
    public String getString(){
        return "Hello, %s!";
    }
}

Sorry but I very new in module with java9

like image 527
Petro Avatar asked Apr 07 '18 11:04

Petro


1 Answers

The compiler (or the IDE) thinks that you have just one module. One module can only have one module descriptor (module-info.java).

You could try the following directory structure:

module1/
  module-info.java
  com/
    test/
      test1/
        Client.java
module2/
  module-info.java
  com/
    test/
      test2/
        Provider.java

Each of the top-level module1 and module2 directories are module directories, so you would have 2 modules.

First module descriptor

module module1 {
    requires module2;
}

Second module descriptor

module module2 {
    exports com.test.test2;
}
like image 153
Roman Puchkovskiy Avatar answered Oct 08 '22 17:10

Roman Puchkovskiy