This works:
mkdir -p foo/foo
echo "module foo {}" > foo/module-info.java
echo 'package foo; public class Main { public static void main(String ... args) { System.out.println("foo!"); } }' > foo/foo/Main.java
$JAVA_HOME/bin/javac -d foo foo/module-info.java foo/foo/Main.java
$JAVA_HOME/bin/jlink --output image --module-path $JAVA_HOME/jmods:foo --add-modules foo --launcher foo=foo/foo.Main
No error, and ./image/bin/foo outputs "foo!" as expected
Doing this in a directory not named foo, however, fails:
mkdir -p classes/foo
echo "module foo {}" > classes/module-info.java
echo 'package foo; public class Main { public static void main(String ... args) { System.out.println("foo!"); } }' > classes/foo/Main.java
$JAVA_HOME/bin/javac -d classes classes/module-info.java classes/foo/Main.java
$JAVA_HOME/bin/jlink --output other_image --module-path $JAVA_HOME/jmods:classes --add-modules foo --launcher foo=foo/foo.Main
=>
Error: jdk.tools.jlink.plugin.PluginException: java.io.IOException: module-info.class not found for foo module
It seems jlink derives some notion of the module name from the directory entry of the module classes on the module-path, which appears to be a bug. Information about module names should be derived from the module-info.class of the modules added to the module-path.
mkdir -p foo/foo
echo "module foo {}" > foo/module-info.java
echo 'package foo; public class Main { public static void main(String ... args) { System.out.println("foo!"); } }' > foo/foo/Main.java
$JAVA_HOME/bin/javac -d foo foo/module-info.java foo/foo/Main.java
$JAVA_HOME/bin/jlink --output image --module-path $JAVA_HOME/jmods:foo --add-modules foo --launcher foo=foo/foo.Main
No error, and ./image/bin/foo outputs "foo!" as expected
Doing this in a directory not named foo, however, fails:
mkdir -p classes/foo
echo "module foo {}" > classes/module-info.java
echo 'package foo; public class Main { public static void main(String ... args) { System.out.println("foo!"); } }' > classes/foo/Main.java
$JAVA_HOME/bin/javac -d classes classes/module-info.java classes/foo/Main.java
$JAVA_HOME/bin/jlink --output other_image --module-path $JAVA_HOME/jmods:classes --add-modules foo --launcher foo=foo/foo.Main
=>
Error: jdk.tools.jlink.plugin.PluginException: java.io.IOException: module-info.class not found for foo module
It seems jlink derives some notion of the module name from the directory entry of the module classes on the module-path, which appears to be a bug. Information about module names should be derived from the module-info.class of the modules added to the module-path.