I try to learn about the modules introduced in java 9. I try to create a runnable Jar. I have the main module, which I want to run and one dependendency module, helloWorldModule.
Module: mainModule main/Main.java
public class Main {
public static void main(String[] args) {
Greeter greeter = new Greeter();
greeter.sayHello();
}
}
module mainModule {
requires helloWorldModule;
}
Module: helloWorldModule helloWorld/Greeter.java
public class Greeter {
public void sayHello(){
System.out.println("Hello there!");
}
}
module helloWorldModule {
exports helloWorld;
}
I've exported the modules to two jars. I can run it like that without any problems.
java --module-path lib --module mainModule/main.Main
But I have to have both modules inside my custom lib folder to make that work. On my research about that, I found here, that one Module is always compiled into one jar. This means, that I can not put my helloWorldModule inside the main module jar file, but as the mainModule requires that helloWorldModule, I can't create a runnable JAR file.
What is the correct way to package my program into a runnable file now?