HahnSolo
HahnSolo

Reputation: 125

Java 9 Module System

I'm trying to learn the new module features of java 9. I don't think I'm doing the requires/exports thing right because intelliJ is giving me red text on my imports unless I add the dependencies in the project structure window, which I'm pretty sure is the wrong way to go. Below is my file structure

app  
--src  
----start  
------main.java  
----module-info.java  

hello  
--src  
----hello  
------Hello.java  
----module-info.java

This is the module-info for app:

module name {
    requires hello;
}

This is the module-info for hello:

module name {
    exports hello;
}

Upvotes: 1

Views: 846

Answers (1)

Jacob G.
Jacob G.

Reputation: 29730

Choosing name as the name for both Java modules isn't a good idea (it might not compile if you try to require a different Java module with the same name).

It also seems that you're attempting to require a package hello, but you should be requiring the other Java module. For this reason, I recommend you rewrite the module-info.java file in app to be the following:

module app {
    requires hello;
}

And rewrite the module-info.java file in hello to be the following:

module hello {
    exports hello;
}

Upvotes: 1

Related Questions