How to add external Jar in modular JavaFX 11 project correctly?

+2 votes

I'm using Java 11 and JavaFX 11. So my JavaFX project contains module-info.class with lines like:

module checker {
    requires javafx.fxml;
    requires javafx.controls;
    requires TextInputProgram; // this is external jar that I added in modular JavaFX project
    opens sample;
    exports sample; // package of program
}

And I want to build artifacts to get jar including external jar and javafx program via Java 11 following this tutorial.

The problem is:
when I'm writting the command:

dir /s /b src\*.java > sources.txt & javac --module-path %PATH_TO_FX% -d mods/checker @sources.txt & del sources.txt

or

dir /s /b src\*.java > sources.txt & javac --module-path %PATH_TO_FX_MODS% -d mods/checker @sources.txt & del sources.txt

I'm getting:

D:\IdeaProject\checker>dir /s /b src\*.java > sources.txt & javac --module-path %PATH_TO_FX_MODS% -d mods/checker @sources.txt & del sources.txt
D:\IdeaProject\checker\src\module-info.java:4: error: module not found: TextInputProgram
    requires TextInputProgram;
             ^
1 error

Before it I set two paths succesfully:

set PATH_TO_FX="path\to\javafx-sdk-12.0.2\lib"
set PATH_TO_FX_MODS="path\to\javafx-jmods-12.0.2"

Can someone explain how to get Jar that will include JavaFX program and external jar using Java 11?

Aug 8 in Java by invzbl3
328 views
Hey @invzbl3 check If you are using the correct version of java and JavaFX version that you have set the path to. Are you using java 11 and JavaFX 11? but i see your path has been set to point to JavaFX12.
Hey @Sirajul. I specified own versions by the same principle:
openjfx-11.0.2_windows-x64_bin-jmods
openjfx-11.0.2_windows-x64_bin-sdk

The problem is that module isn't found for external jar which I don't know how correctly to set as module to include in final executable jar. I added this external jar as lib in Project Structure, in module-info.class, but still cmd is complaining about it.

I guess you should try this. Add the path to the external jar file here( instead of putting it in a lib ) in this particular operation in the same way as you have specified the JavaFX path.

D:\IdeaProject\checker>dir /s /b src\*.java > sources.txt & javac --module-path %PATH_TO_FX_MODS% -d mods/checker @sources.txt & del sources.txt

you might find this helpful! Check this out: 

Here they have directly added the external dependency jar (logic-1.0-sanpshot.jar) using the CLI instead of the conventional way! Have a look: https://dzone.com/articles/javafx-on-jdk-11

Thanks, Karan! It's actually good example.
Glad that it was helpful @Invzbl3

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Java

0 votes
3 answers

How can I add new elements to an Array in Java

String[] source = new String[] { "a", ...READ MORE

answered Sep 19, 2018 in Java by Sushmita
• 6,880 points
162 views
+2 votes
10 answers

How to import a jar file in Eclipse?

To import jar file in your Eclipse ...READ MORE

answered May 15, 2018 in Java by sharth
• 3,350 points
76,746 views
0 votes
2 answers

How can we add leading zeros to the number in Java?

From Java 1.5 you can use the String.format method. ...READ MORE

answered Aug 26 in Java by Sirajul
• 40,980 points
430 views
0 votes
10 answers

What is the correct way to add external Jars to IntelliJ IDEA Project?

The best way is to add the ...READ MORE

answered Dec 10, 2018 in Java by Nabarupa
26,234 views
0 votes
1 answer

How can we add local .jar file dependency to build.gradle file?

You can refer the below code if ...READ MORE

answered Jun 27, 2018 in Java by Akrati
• 960 points
1,638 views
0 votes
1 answer

How to add row in JTable

To create a table: JTable table = new ...READ MORE

answered Jun 29, 2018 in Java by Akrati
• 960 points
49 views
0 votes
1 answer

Retrieving the path of a running jar file

Its quite simple. Try using the below ...READ MORE

answered May 25, 2018 in Java by geek.erkami
• 2,640 points
1,512 views
0 votes
1 answer

How to run the JAR files in windows?

Following are the steps to run the ...READ MORE

answered May 28, 2018 in Java by parth295
• 4,640 points
111 views
0 votes
2 answers

How can we add the local JAR files to the Maven Project in Java?

Firstly I would like to give credit ...READ MORE

answered Nov 5, 2018 in Java by Sushmita
• 6,880 points
349 views
0 votes
1 answer

How to run a JAR file in Java?

The command given below will help you ...READ MORE

answered Jun 1, 2018 in Java by parth295
• 4,640 points
1,315 views