0

I am getting this Error: Module java.base not found while trying to use jlink.

These are the 2 things I have tried so far

/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/jlink --module-path "%JAVA_HOME%\jmods":mods --add-modules com.tutorialspoint.greetings,java.base --output customjre
Error: Module java.base not found

/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/jlink --module-path "%JAVA_HOME%\jmods":mods --add-modules com.tutorialspoint.greetings,java.base@9.0.4 --output customjre
Error: Module java.base@9.0.4 not found

My module contains this.

module com.tutorialspoint.greetings { 
    requires java.base;
}

I followed this tutorial for making modules exactly except I added the requires java.basic. https://www.tutorialspoint.com/java9/java9_module_system.htm

I tried it without requires java.base and still get the same problem. Any ideas? I am new to JLink and Java9 and wanted to try it since java8 doesn't have Jlink.

Maybe it's how I am referencing to JLink in the directory itself?

PHPirate
  • 7,023
  • 7
  • 48
  • 84
coloradoman
  • 341
  • 1
  • 5
  • 11
  • try using an absolute path to the JDK's default jmods instead of `%JAVA_HOME%\jmods` for your module-path with the first command. By the way, you don't really need to explicitly mention the `requires java.base;` directive. – Naman Oct 21 '20 at 06:52
  • Thanks @Naman I didn't think about the JAVA_HOME path being wrong. Yeah I tried it with and without the requires java.base with no luck. Let me try that JAVA_HOME change. – coloradoman Oct 21 '20 at 12:10
  • @Naman /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/jlink --module-path "/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home\jmod":mods --add-modules com.tutorialspoint.greetings --output customjre Error: Module java.base not found, required by com.tutorialspoint.greetings Still no luck. Note that I did also change jmods to jmod since it appears thats what it is called. – coloradoman Oct 21 '20 at 13:01
  • It is interesting the error has changed slightly. It now says "required by com.tutorialspoint.greetings" – coloradoman Oct 21 '20 at 13:08
  • I just tired the exact command (changed for windows ; instead of :) and it worked. Not sure why it was broken on mac. – coloradoman Oct 21 '20 at 14:08
  • 2
    I’m very sure that the Windows syntax `%JAVA_HOME%` does not work on MacOS. Depending on the shell, it would be something like `${JAVA_HOME}`. Also, don’t use backslash as separator, as in `\jmods`. – Holger Oct 21 '20 at 15:13

1 Answers1

0

The problem comes from the fact that the path of the module is poorly defined.

If you are on macos, the correct syntax is:

jlink --module-path "mods:$JAVA_HOME/jmods" --add-modules com.tutorialspoint.greetings --output customjre

Make sure the JAVA_HOME variable is set before running the jlink.

Also, it is not necessary to define the requires clause with the java.base module in your module because the java.base module is implicitly added in all modules.

Peter Csala
  • 17,736
  • 16
  • 35
  • 75