JavaFX2将launch4j包装为Maven插件 [英] JavaFX2 wrapping launch4j as maven plugin

查看:51
本文介绍了JavaFX2将launch4j包装为Maven插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用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>

谢谢您的帮助.

解决方案

我怀疑问题是您指定的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>

Hello I am trying to wrap an javaFX-jar with launch4j maven plugin.

But the execution fails:

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

It looks like the exe cannot find the jfxruntime. If I start the program with "java -jar ..." it works fine.

Here is partial of my 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>

Thank you for your help.

解决方案

I suspect the problem is the version of the JRE you are specifying. JavaFX (version 2.2) wasn't bundled with the JRE until 1.7 update 6. I think your minVersion setting is probably accepting a JRE that is update 5 or earlier and the JavaFX libraries aren't installed (correctly). Try specifying <minVersion>1.7.0_09</minVersion> and see if that works.

I seem to remember that if you have a 64bit update 6 and a 32bit update 5 launcher4j will pick the 32bit version even though the 64bit would be better. That might explain why it works in your development environment but not when built.

Other than that your POM configuration looks pretty much the same as mine which works fine.

Edit

This works for me...

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

这篇关于JavaFX2将launch4j包装为Maven插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆