2

The error module {a} does not "opens {package}" to module {B} has been asked before, where an explanation and solution was provided.

The solution was to add the following --add-opens VM argument to the command line when running the jar file like so: java -jar --add-opens=java.base/java.lang=ALL-UNNAMED some_jar_file.jar

I have a JavaFX program running Java-11.0.6 and javafx-sdk-14, built in Eclipse Version: 2019-09 R (4.13.0). When I export my project as a runnable jar file, the aforementioned fix works when I run the jar file from command prompt.

However, when I try to apply the VM argument fix to Eclipse so that I can run my program inside of Eclipse, I get the original module {a} does not "opens {package}" to module {B} error:

enter image description here

Am I misunderstanding the fix, using eclipse VM arguments incorrectly, or is it an issue with Eclipse? My company has the 2020-06 version of Eclipse that I could try, but since modules were introduce in Java9 years ago, I doubt it will help.

Note: I've made sure my Eclipse is configured to use Java 11 as its VM:

enter image description here

Edit 1: My command line from Eclipse is as follows: C:\Program Files\Java\jdk-11.0.6\bin\javaw.exe --add-opens=java.base/java.lang=ALL-UNNAMED -Dfile.encoding=Cp1252 -p "C:\Users\BL89306\eclipse-workspace\cto_emi_aat\bin;C:\Program Files\Java\javafx-sdk-14\lib\javafx.base.jar;C:\Program Files\Java\javafx-sdk-14\lib\javafx.controls.jar;C:\Program Files\Java\javafx-sdk-14\lib\javafx.fxml.jar;C:\Program Files\Java\javafx-sdk-14\lib\javafx.graphics.jar;C:\Program Files\Java\javafx-sdk-14\lib\javafx.media.jar;C:\Program Files\Java\javafx-sdk-14\lib\javafx.swing.jar;C:\Program Files\Java\javafx-sdk-14\lib\javafx.web.jar;C:\Program Files\Java\javafx-sdk-14\lib\javafx-swt.jar;C:\Users\BL89306\eclipse-workspace\cto_emi_aat\lib\com.ibm.mq.allclient-9.2.0.1.jar;C:\Users\BL89306\eclipse-workspace\cto_emi_aat\lib\gson-2.8.6.jar;C:\Users\BL89306\eclipse-workspace\cto_emi_aat\lib\ikonli-javafx-11.3.5-sources.jar;C:\Users\BL89306\eclipse-workspace\cto_emi_aat\lib\ikonli-javafx-11.3.5.jar;C:\Program Files\Microsoft JDBC DRIVER 6.0 for SQL Server\sqljdbc_6.0\enu\jre8\sqljdbc42.jar;C:\Users\BL89306\eclipse-workspace\cto_emi_aat\lib\jaxb-api-2.3.1.jar" -m AAT/com.thehartford.aat.gui.AATApp

Brandon Loehle
  • 256
  • 1
  • 3
  • 16
  • When you hit the _Show Command Line_ button, you can see what Eclipse runs on the command line. Please check, if the command line is correct. If not, add it to your question. By the way, instead adding it as VM argument in each run configuration, you should configure it on the project level: _Project > Properties: Java Build Path_, tab _Module Dependencies_. – howlger Dec 01 '20 at 17:33
  • @howlger I've added the command line. Looks like it uses `-m` instead of `-jar`. Perhaps that's the root cause? – Brandon Loehle Dec 01 '20 at 17:46
  • 1
    `-m` is for the main class location: `-m /`, which shows that at least your main class is in the `AAT` module, not in the `ALL-UNNAMED` module. `-jar` is for a JAR file, but a run configuration uses directly the classes of the output folder that are incremental compiled on saving `.java` source files. – howlger Dec 01 '20 at 18:25

1 Answers1

3

--add-opens=java.base/java.lang=ALL-UNNAMED opens the java.lang package of the java.base module to the ALL-UNNAMED module, which is everything on the classpath. But you have nothing on the classpath. If all your code is in the AAT module (where your class with the main method is), it's:

--add-opens=java.base/java.lang=AAT
howlger
  • 31,050
  • 11
  • 59
  • 99