admin管理员组文章数量:1389897
Bit of a Java noob here, so please excuse my lack of understanding and terminology. I'm trying to package my maven project with JavaFX into a fat Jar. I've done everything I can see to do from various places online.
Running mvn package creates distcalc-1.0.jar in \target, but opening it gives "A Java exception has occured". Somewhere online someone said to try running "mvn package shade:shade". doing so creates three jars, distcalc-1.0, original-distcalc-1.0, and distcalc-1.0-shaded.jar, which also gives the same error. Any thoughts or help would be much appreciated.
I know packaging it like this might not always be the best practice way of doing things, but this is an incredibly simple program (one class, one method, it's literally just a preset function with input fields and a calculate button). It's just for me and one or two coworkers running the same OS as I developed it, so I'm not too worried, I just want a fairly simple way to use it.
I'm using maven shade, and have this in my pom.xml:
<plugin>
<groupId>.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation=".apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>.example.distcalculator.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
I've seen some people say that the Main class extending application causes an issue, and the fix most people said worked was to change Main.java to something else (say, App.java) and have Main.java call that:
package .example.distcalculator;
public class Main {
public static void main(String[] args) {
App.main(args);
}
}
The code works fine inside intelliJ when I run it. I've run mvn clean and then run "mvn javafx:run" from command line the program opens.""
UPDATE: part of what may have been screwing with it is microsoft deciding to try to sync my project to onedrive... I've got it on my device now. Now, distcalc-1.0.jar is still giving the Java exception, but running "java -jar distcalc-1.0.jar" opens the program fine. However, doing so does give a warning in the command prompt saying WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @63e244f0'
UPDATE 2: Right-clicking and running with JDK runs it, but it won't run with JRE. My JRE and JDK are up to date... Any clue as to why this would happen?
Bit of a Java noob here, so please excuse my lack of understanding and terminology. I'm trying to package my maven project with JavaFX into a fat Jar. I've done everything I can see to do from various places online.
Running mvn package creates distcalc-1.0.jar in \target, but opening it gives "A Java exception has occured". Somewhere online someone said to try running "mvn package shade:shade". doing so creates three jars, distcalc-1.0, original-distcalc-1.0, and distcalc-1.0-shaded.jar, which also gives the same error. Any thoughts or help would be much appreciated.
I know packaging it like this might not always be the best practice way of doing things, but this is an incredibly simple program (one class, one method, it's literally just a preset function with input fields and a calculate button). It's just for me and one or two coworkers running the same OS as I developed it, so I'm not too worried, I just want a fairly simple way to use it.
I'm using maven shade, and have this in my pom.xml:
<plugin>
<groupId>.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation=".apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>.example.distcalculator.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
I've seen some people say that the Main class extending application causes an issue, and the fix most people said worked was to change Main.java to something else (say, App.java) and have Main.java call that:
package .example.distcalculator;
public class Main {
public static void main(String[] args) {
App.main(args);
}
}
The code works fine inside intelliJ when I run it. I've run mvn clean and then run "mvn javafx:run" from command line the program opens.""
UPDATE: part of what may have been screwing with it is microsoft deciding to try to sync my project to onedrive... I've got it on my device now. Now, distcalc-1.0.jar is still giving the Java exception, but running "java -jar distcalc-1.0.jar" opens the program fine. However, doing so does give a warning in the command prompt saying WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @63e244f0'
UPDATE 2: Right-clicking and running with JDK runs it, but it won't run with JRE. My JRE and JDK are up to date... Any clue as to why this would happen?
Share Improve this question edited Mar 15 at 16:34 Miles Leech asked Mar 15 at 15:39 Miles LeechMiles Leech 12 bronze badges 2 |1 Answer
Reset to default 1The documentation for OpenJFX.io has one using Maven to run the program with a command such as mvn clean javafx:run
In this scenario, a plugin has been included in the pom.
Their documentation also has a section on running the program via the CLI, but it involves adding quite a few additional parameters to the javac and java commands in order to accommodate the javafx modules. The example they give (once properly compiled) is the following:
java --module-path "%PATH_TO_FX%;mods" -m hellofx/hellofx.HelloFX
Getting this all to work is no mean feat! But I have had success using their downloads and documentation. I haven't tried following their jlink documentation yet.
本文标签: javaStruggling to create a Jar for my simple program with Maven ShadeStack Overflow
版权声明:本文标题:java - Struggling to create a Jar for my simple program with Maven Shade - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744611307a2615671.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
java -jar distcalc-1.0.jar
. This will show you what the actual exception is. Once you have that, edit your question, and paste the entire stack trace into your question (as code-formatted text, please, not as an image). That exception is critical diagnostic information which will tell you, and us, exactly what is going wrong. – VGR Commented Mar 15 at 15:58JavaFX WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @...'
– jewelsea Commented Mar 15 at 20:07