您好我正在尝试使用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>
感谢您的帮助。
答案 0 :(得分:1)
我怀疑问题是您指定的JRE的版本。在1.7更新6之前,JavaFX(版本2.2)未与JRE捆绑在一起。我认为您的minVersion设置可能正在接受更新5或更早版本的JRE,并且未正确安装JavaFX库。尝试指定<minVersion>1.7.0_09</minVersion>
并查看是否有效。
我似乎记得如果你有64位更新6和32位更新5 launcher4j将选择32位版本,即使64位会更好。这可以解释为什么它在您的开发环境中有效,但在构建时无效。
除此之外,你的POM配置与我的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>