最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Struggling to create a Jar for my simple program with Maven Shade - Stack Overflow

programmeradmin1浏览0评论

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
  • 2 Open a command window, change to your project’s target directory, and run 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:58
  • Potential duplicate: JavaFX WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @...' – jewelsea Commented Mar 15 at 20:07
Add a comment  | 

1 Answer 1

Reset to default 1

The 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.

发布评论

评论列表(0)

  1. 暂无评论