I struggled through the process of creating an executable jar as well, but this workaround is what worked for me, and I hope it works for you as well:
First of all, instead of using the jar
plugin, I used the shade
plugin in pom.xml
, which creates a "fat jar" or "uber jar" that contains your classes and all of the dependencies within the jar. This way, your jar will be included with all the necessary javafx
packages and classes. That is, if you include these in the <dependencies>
section:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
... or whatever else of the javafx
libraries you need in order for your application to run.
Simply doing this does not work, however. I'm assuming that your main class Entry extends Application
?
I'm guessing the jar
needs to know the actual Main class that does not extend Application, so I just created another Main class called SuperMain
(it was only a temporary name) that calls my original main class, which is Main
:
// package <your.package.name.here>
public class SuperMain {
public static void main(String[] args) {
Main.main(args);
}
}
whereas in your case it's Entry
.
So in my pom.xml, I have a plugin called shade
that looks like this:
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>my.package.name.SuperMain</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
and there should be a jar that's "shaded" after you execute mvn package
.
Thanks to the answer to this post: JavaFX 11 : Create a jar file with Gradle
Hope this helps!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…