如何从javaFX项目制作jar文件 [英] How to make jar file from javaFX project

查看:369
本文介绍了如何从javaFX项目制作jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个javaFX项目,我正在其中使用Eclipse IDE.这是使用Spring的Maven项目. 我的目标是从该项目中创建可运行的jar文件(dekstop应用程序).

I have javaFX project, with which i'm working on Eclipse IDE. This is Maven project with using of Spring. My goal is to make runable jar file (dekstop application) from this project.

如果我像其他任何Java项目一样将我的应用程序导出到jar文件,那么我会在收到错误消息时收到此消息:

If i export my application to jar file like any other java project, then i recieve this on error:

C:\eclipse\projjars>java -jar EqMan.jar
Exception in thread "main" java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Can't load library: C:\eclipse\bin\glass.dll
        at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:276)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:122)
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:163)
        at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
        at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: Can't load library: C:\eclipse\bin\glass.dll
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.load0(Unknown Source)
        at java.lang.System.load(Unknown Source)
        at com.sun.glass.utils.NativeLibLoader.loadLibraryFullPath(NativeLibLoader.java:143)
        at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:56)
        at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:31)
        at com.sun.glass.ui.Application$1.run(Application.java:75)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.glass.ui.Application.loadNativeLibrary(Application.java:73)
        at com.sun.glass.ui.Application.loadNativeLibrary(Application.java:85)
        at com.sun.glass.ui.win.WinApplication.<clinit>(WinApplication.java:33)
        at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatformFactory.java:20)
        at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatformFactory.java:17)
        at com.sun.glass.ui.Application.Run(Application.java:108)
        at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:266)
        ... 5 more

如果我尝试使用javafxpackager制作jar文件,则会收到此错误消息:

If i'm trying to make jar file with javafxpackager, i recieve this one error:

C:\eclipse\workspace\equification>javafxpackager -makeall -appclass ru.igs.ava.equification.EquificationFX -name "Equification" -width 800 -height 600
warning: [options] bootstrap class path not set in conjunction with -source 1.5
C:\eclipse\workspace\equification\src\main\java\ru\igs\ava\equification\EqConfigureRole.java:5: error: package org.springframework.context does not exist
import org.springframework.context.ApplicationContext;
C:\eclipse\workspace\equification\src\test\java\ru\igs\ava\equification\AppTest.java:11: error: cannot find symbol
    extends TestCase
            ^
//and the same error for every class, which is added to my project as maven dependency.

那么,如何在不将项目转换为NetBeans项目的情况下制作可运行的jar文件?

So, how can i make runable jar file without converting my project to NetBeans project?

推荐答案

看到您正在使用Maven进行构建时,还可以使用Maven来启动JavaFX打包.为此,请使用Maven antrun 插件调用示例maven pom .

Seeing as you are using Maven for your builds, you can also use Maven to initiate the JavaFX packaging. To do this use the Maven antrun plugin to invoke the JavaFX ant tasks to generate a jar for your application with an embedded JavaFX launcher. Here is a sample maven pom to do this.

您在运行javafx打包程序时出现错误是由于未正确设置打包程序的类路径.

Your errors in running the javafx packager are due to not appropriately setting the classpath for the packager. An example of how to set the classpath for the javafx packager to package an application which relies on dependent lib jars is in this build script.

不满意的链接错误是因为在您运行应用程序时,相对于jfxrt.jar的运行时位置,您没有在../bin目录中包括所需的lib dll.您可能还没有正确地使用JavaFX启动器打包应用程序(通过执行推荐的javafx ant任务或javafxpackager命令来生成JavaFX应用程序jar).

The unsatisfied link errors are because you are not including the required lib dll's in a ../bin directory relative to the runtime location of jfxrt.jar when you run your app. You also might not be correctly packaging your application with a JavaFX launcher (via executing the recommended javafx ant tasks or javafxpackager commands to generate your JavaFX application jar).

更新

对于基于Maven的JavaFX应用程序构建,您现在可以使用 Maven JavaFX插件.

For Maven based builds of JavaFX applications, you can now use a Maven JavaFX plugin.

这篇关于如何从javaFX项目制作jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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