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, 2019 in Java by invzbl3
5,910 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
1 answer

How to add local jar files to a Maven project?

Hello @kartik, You can add local dependencies directly ...READ MORE

answered Jul 28, 2020 in Java by Niroj
• 82,840 points
2,284 views
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,920 points
13,192 views
+5 votes
11 answers

How to import a jar file in Eclipse?

Click on File > Import. The Import ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,140 points
359,781 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, 2019 in Java by Sirajul
• 59,230 points
5,161 views
+1 vote
13 answers

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

Adding custom JAR files to the EAR project Copy the custom JAR to the ...READ MORE

answered Dec 10, 2020 in Java by Nikita
187,507 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
5,363 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,680 points
10,705 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 Parth
• 4,640 points
1,141 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,920 points
11,791 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 Parth
• 4,640 points
7,421 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP