Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 618
2 revs Avatar asked Mar 24 '26 05:03

2 revs


2 Answers

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:

  • https://docs.oracle.com/en/java/javase/20/docs/specs/man/javac.html#standard-options
  • "maven.compiler.release" as an replacement for source and target?
  • https://ant.apache.org/manual/Tasks/javac.html
  • https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html
  • https://docs.gradle.org/current/userguide/building_java_projects.html#sec:compiling_with_release
like image 139
nineninesevenfour Avatar answered Mar 25 '26 18:03

nineninesevenfour


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."

like image 34
2 revs Avatar answered Mar 25 '26 17:03

2 revs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!