Java warning: [options] system modules path not set in conjunction with -source 11
Asked Answered
F

6

8

This machine has had multiple version of Java JDK installed and multiple version of multiple IDEs (Netbeans, IntelliJ, Eclipse, etc.) Most recently, I have added JDK 15.0.2 and Netbeans 12.2. When trying to compile a simple "Hello World", this is the output that results:

ant -f C:\\Data\\NetBeans\\grading\\TestGrading -Dnb.internal.action.name=run.single -Djavac.includes=testgrading/HelloWorld.java -Drun.class=HelloWorld run-single

init:

Deleting: C:\Data\NetBeans\grading\TestGrading\build\built-jar.properties

deps-jar:

Updating property file: C:\Data\NetBeans\grading\TestGrading\build\built-jar.properties

Compiling 1 source file to C:\Data\NetBeans\grading\TestGrading\build\classes

**warning: [options] system modules path not set in conjunction with -source 11**

**1 warning**

compile-single:

run-single:

Hello World!

BUILD SUCCESSFUL (total time: 1 second)

As you can see, the file compiles and runs, but the warning is causing me concern. I have not been able to find a similar warning in my searches... (all of the warnings refer to "bootstrap class path not set" instead of "system modules path not set"

I have updated my Environment Variable to reflect the most current JDK with this entry: JAVA_HOME=C:\Program Files\Java\jdk-15.0.2

What setting am I missing that wasn't properly updated as I've updated my JDK and my IDE? Or am I completely looking in the wrong places? Or do I need to fully uninstall previous versions and, if so, what will that do to previous code written using those previous versions that I'd still like to retain?

Thanks in advance!

Firstclass answered 5/2, 2021 at 17:49 Comment(5)
Consider reading up the modules feature. It seems recent version of java are throwing the warnings and suggesting that you use the modules feature in your code. tutorials.jenkov.com/java/modules.htmlHaversack
Jens -thank you for your comment and your pitch for Java Modules, but this doesn't answer my specific question about this specific warning message and how I can go about resolving it. Warning message should be easily decipherable - not cryptic without resource to resolve them.Firstclass
The warning is as with many system messages is indeed cryptic. Assume you are using - source 11 somewhere in the javac command used for the build. Please try adding - - release 11 and rerun the build. That should fix thisHaversack
I stumbled on the issue and the fix! While the new install changed the Java Platform in the Libraries properties to correctly point to JDK 15 as the new (Default), in the Sources area, towards the bottom, it left the Source/Binary Format still showing JDK 11. Changing this manually to JDK 15 made the warning go away. The warning message should have said something to the effect of "Source/Binary Format" does not match Library Java Platform - check corresponding versions."Firstclass
@WeberElnc The warning doesn't say about source format since in java it's a perfectly valid scenario to use a later version of jdk (15) and want to compile with compatibility level of an older version (11). Usually changing the version for compiling can be non trivial exercise especially if the source code uses classes or methods that have been deprecated in later versions. In such a case changing compile version would involve code rewrite.Haversack
F
8

I stumbled on the issue and the fix! While the new install changed the Java Platform in the Libraries properties to correctly point to JDK 15 as the new (Default), in the Sources area, towards the bottom, it left the Source/Binary Format still showing JDK 11. Changing this manually to JDK 15 made the warning go away. The warning message should have said something to the effect of "Source/Binary Format" does not match Library Java Platform - check corresponding versions."

Firstclass answered 14/2, 2021 at 0:54 Comment(2)
Took me a little effort to understand your solution (which worked - thanks!), so to clarify for others: In Netbeans, right click on project and go to Properties. Then look at Sources. As stated above, the Source / Binary Format will specify an older version of the JDK, so use the dropdown to update that value (in my case, JDK 11 --> JDK 15).Solingen
In intellij 2023+ I had to open project settings, gooto Modules -> Sources and change the "Language level" there for java inspectionsIsochromatic
H
10

I am posting a new anwser to this question, because I feel something important has been overlooked here before but should be pointed out to readers coming across in the future. Let's try to answer the actual question first and then give a more detailed explanation.

What setting am I missing that wasn't properly updated as I've updated my JDK and my IDE? Or am I completely looking in the wrong places?

This message is an output of javac (the Java compiler) and created (since JDK14) by default when the argument -source diverges from the version of the JDK from which javac was started. There is not one solution, you have to think first, if -source (and -target as well) are still up to date for your needs. That means:

  • What is the JRE (or JDK) version I want/need to support my artifacts to run on?

Remark1: -source cannot be completely treated independently from -target, because the first one must be <= the second one (you cannot develop sources against JDK 17 and run on JDK 8 for example - that would be cool, but is not supported).

Remark2: In Maven the parameters are named maven.compiler.source and maven.compiler.target, in Gradle sourceCompatibility and targetCompatibility, I don't know for Ant (pls. check third link below).

If you want/need to keep the current compatibility settings then you have basically two options:

  • (recommended) Replace -source and -target by --release. This option implicitly includes a check against the API version of the targeted JRE/JDK! Therefor the message goes away as well.
  • Add addtionally the --system option to javac pointing to a JDK of the same version as --source. Setting that parameter allows javac to take the API into account as well. It is roughly a replacement for -bootclasspath with the difference that it doesn't point to a "rt.jar", but to the root directory, like JAVA_HOME would do. Think of it as a "old JAVA_HOME" option.

If you can switch to a newer JDK/JRE version for runtime entirely, of course -source and -target can be adapted accordingly (I'd recommend to use --release instead anyway).

The actual problem (and that's why I am writing so much), is that neither -source nor -target include a check against the API, hence the warning. For example (without API check through --release or --system) it would be possible to compile with -target 1.7 and reference java.util.function.Consumer at the same time, which has been added in JDK 8. You might not even notice locally (neither in CI), when running tests with the newer JDK. It just stops working in production.

see also:

Hornbeam answered 27/9, 2023 at 0:33 Comment(0)
F
8

I stumbled on the issue and the fix! While the new install changed the Java Platform in the Libraries properties to correctly point to JDK 15 as the new (Default), in the Sources area, towards the bottom, it left the Source/Binary Format still showing JDK 11. Changing this manually to JDK 15 made the warning go away. The warning message should have said something to the effect of "Source/Binary Format" does not match Library Java Platform - check corresponding versions."

Firstclass answered 14/2, 2021 at 0:54 Comment(2)
Took me a little effort to understand your solution (which worked - thanks!), so to clarify for others: In Netbeans, right click on project and go to Properties. Then look at Sources. As stated above, the Source / Binary Format will specify an older version of the JDK, so use the dropdown to update that value (in my case, JDK 11 --> JDK 15).Solingen
In intellij 2023+ I had to open project settings, gooto Modules -> Sources and change the "Language level" there for java inspectionsIsochromatic
K
3

I was getting an error which brought me to this SO question. I read this and some docs. I configured the following in my pom.xml:

<maven.compiler.release>17</maven.compiler.release>

Which replaced:

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>

The compiler warning went away.

Kimberleykimberli answered 18/6, 2024 at 2:5 Comment(0)
S
0

It is sometimes happened because of java updates. When the newer version is needed,it says you to remove the older version. If you didn't do that this cause come confusing. You can better use older versions to solve this problem. Maybe this can help you.

Scarabaeid answered 5/2, 2021 at 18:28 Comment(1)
Isilacar - unfortunately, the install process of the newer version did not warn about removing the old version and did not say that there would be any issues. Shouldn't Java documentation include a way to troubleshoot these warnings?Firstclass
B
0

I had this exact same warning, which in my case ended up as an error and caused build to fail when runnning mvn commands. I was using jdk 16 and also had 11 installed. In my case, nothing has fixed it except to fully uninstall java from my mac and reinstall the versions I needed from https://adoptopenjdk.net/.

Blessington answered 5/8, 2021 at 8:4 Comment(0)
Y
-2

You need to update your JAVA_HOME environment variable.

On Mac update your ~/.bash_profile or ~/.zshrc. Make sure you have the version you want installed and make -v## the version you want to use. For example,

To use Java 11,

export JAVA_HOME=`/usr/libexec/java_home -v11` 

To use Java 17,

export JAVA_HOME=`/usr/libexec/java_home -v17` 

On Windows change you system environment variable to your new java version.

Heres how! (Confluence)

Yawmeter answered 6/10, 2022 at 15:3 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.