0

你好我正在尝试用launch4j maven插件包装一个javaFX-jar。

但执行失败:

Exception in thread "main" java.lang.NoClassDefFoundError: javafx/applicatio
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(Unknown Source)
   at java.security.SecureClassLoader.defineClass(Unknown Source)
   at java.net.URLClassLoader.defineClass(Unknown Source)
   at java.net.URLClassLoader.access$100(Unknown Source)
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 13 more

看起来exe找不到jfxruntime。如果我用“java -jar ...”启动程序,它工作正常。

这是我的 pom.xml 的一部分

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <encoding></encoding>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.zenjava</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>build-jar</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>org.myprogram.Main</mainClass>
                <bundleType>ALL</bundleType>
                <vendor>me</vendor>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.bluestemsoftware.open.maven.plugin</groupId>
            <artifactId>launch4j-plugin</artifactId>
            <version>1.5.0.0</version>
            <executions>
                <execution>
                    <id>l4j-gui</id>
                    <phase>package</phase>
                    <goals>
                        <goal>launch4j</goal>
                    </goals>
                    <configuration>
                        <headerType>gui</headerType>
                        <outfile>target/MyProgram.exe/outfile>
                        <jar>target/${project.artifactId}-${project.version}-jfx.jar</jar>
                        <errTitle>App Err</errTitle>
                        <classPath>
                            <mainClass>org.myprogram.Main</mainClass>
                        </classPath>                            
                        <jre>
                            <minVersion>1.7.0</minVersion>                              
                            <initialHeapSize>128</initialHeapSize>
                            <maxHeapSize>1024</maxHeapSize>
                        </jre>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

感谢您的帮助。

4

1 回答 1

1

我怀疑问题出在您指定的 JRE 版本上。JavaFX(2.2 版)直到 1.7 更新 6 才与 JRE 捆绑在一起。我认为您的 minVersion 设置可能接受更新 5 或更早版本的 JRE,并且未安装(正确)JavaFX 库。尝试指定<minVersion>1.7.0_09</minVersion>并查看是否有效。

我似乎记得,如果您有 64 位更新 6 和 32 位更新 5,那么即使 64 位会更好,launcher4j 也会选择 32 位版本。这可以解释为什么它在您的开发环境中有效,但在构建时无效。

除此之外,您的 POM 配置看起来与我的几乎相同,可以正常工作。

编辑

这对我有用...

<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
    <execution>
        <id>l4j-gui</id>
        <phase>package</phase>
        <goals>
            <goal>launch4j</goal>
        </goals>
        <configuration>
            <dontWrapJar>true</dontWrapJar>
            <headerType>gui</headerType>
            <jar>mapp.jar</jar>
            <outfile>${project.build.directory}/dist/myapp.exe</outfile>
            <errTitle/>
            <cmdLine/>
            <chdir/>
            <priority>normal</priority>
            <downloadUrl>http://java.com/download</downloadUrl>
            <supportUrl/>
            <customProcName>false</customProcName>
            <stayAlive>false</stayAlive>
            <manifest/>
            <icon/>
            <jre>
                <path/>
                <minVersion>1.7.0_09</minVersion>
                <maxVersion/>
                <jdkPreference>preferJre</jdkPreference>
                <initialHeapSize>256</initialHeapSize>
                <maxHeapSize>3000</maxHeapSize>
            </jre>
            <splash>
                <file>${project.basedir}/src/main/build/splash.bmp</file>
                <waitForWindow>true</waitForWindow>
                <timeout>60</timeout>
                <timeoutErr>true</timeoutErr>
            </splash>
            <versionInfo>
                <fileVersion>0.0.0.0</fileVersion>
                <txtFileVersion>${project.version}</txtFileVersion>
                <fileDescription>Desc</fileDescription>
                <copyright>Company 2013</copyright>
                <productVersion>0.0.0.0</productVersion>
                <txtProductVersion>${project.version}</txtProductVersion>
                <productName>My App</productName>
                <companyName>Company</companyName>
                <internalName>myapp</internalName>
                <originalFilename>myapp.exe</originalFilename>
            </versionInfo>
        </configuration>
    </execution>
</executions>

于 2013-06-06T15:23:18.487 回答