Reputation: 341
My JavaFX application is running perfectly well from source but When I'm compiling to a single jar file I get error :
Error: JavaFX runtime components are missing, and are required to run this application.
I'm using Maven as my repository manager and My install with Maven is successful.
Note: In my IntelliJ build artifact I can see that IntelliJ include JavaFX and all its libraries
Upvotes: 17
Views: 39462
Reputation: 1
go to Run then edit configura... then Vm option and add this:
--module-path "path\to\javafx-sdk-22.0.1\lib" --add-modules javafx.controls,javafx.fxml
change the path with your path to JavaFX
for exact execution see : https://www.youtube.com/watch?v=hS_6ek9rTco
Upvotes: 0
Reputation: 1
1 STEP is to create a class name it like you want it should be Main class that would start your program, paste there (in psvm) like GUI.main(args).2 STEP is go to Artifacts and add there all .dll from jfx/bin/ 3 STEP is put the META-INF to src .4 STEP is build artifacts and try to run.But the reason what i have is when i run this (my progr contains sql db) the sqldb creates in running folder but i dont see the main window
Upvotes: 0
Reputation: 229
STEP 1 - In your src. Step 1 add "extra" main I named Launcher as you can see in Step2 image.
STEP 2 - After in the "extra" class create a main and in that call the main of the MainClassJavaFx Step 2
STEP 3 - From project structure add new artifact and select the "extra class" as main and relocate the MANIFEST folder to src and not resources. Step 3
STEP 4 - Add all dll from javafx sdk from your folder Step 4
STEP 5 - Build artifact
This should works.
Upvotes: 0
Reputation: 12370
a) For my maven project the trick was to use an extra starter class that does not inherit from javafx.application.Application:
public class GUIStarter {
public static void main(final String[] args) {
GUI.main(args);
}
}
The JavaFx dependencies are included in my pom.xml as follows:
<!-- JavaFx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics </artifactId>
<version>12</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>12</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>12</version>
</dependency>
In order to include fxml files in your build, you might need to define them as resource:
!-- define JavaFx files as resources to include them in the jar -->
<resource>
<directory>${basedir}/src/main/java/foo/baa/view</directory>
<filtering>false</filtering>
<targetPath>foo/baa/view</targetPath>
</resource>
b) As an alternative, an extra maven plugin "javafx-maven-plugin" could be used to build the javafx appication, see example project at https://openjfx.io/openjfx-docs/#maven (This did not work for me. I have several pom files and want to reference the javafx dependencies in a sub project. My main class could not be found by the javafx-maven-plugin.)
Upvotes: 37
Reputation: 3294
In Java 11 the JavaFX components have been removed into their own SDK, so when you run it won't be able to find them in the runtime.
The JavaFX page has the instructions to get it going: https://openjfx.io/openjfx-docs/#install-javafx
In short, you have to compile / run by adding the javafx modules in, either as options passed on the command line, or using a modular project.
I found that the modular project with Maven and IntelliJ worked best for me. https://openjfx.io/openjfx-docs/#IDE-Intellij
In the modular method you have a module-info.java
file that describes all the modules that your project "requires", and allows you to "open" them to other modules. If you have a bunch of Maven dependencies you have to add them in the requires list too though. (IntelliJ can make this easy - find the error about no requires in the code and alt-enter)
Once everything was working with modules etc, I had to make a Fat Jar using I think the Maven shade plugin, to put everything together. Then it would work running the jar from the command line.
However, after getting my Java 11 code @#$%@# working after 2 days of pain, I went back to Java 8 (using correto SDK for latest version) as Java 11 doesn't have packaging and IntelliJ can't do it for you.
Upvotes: -1