简体   繁体   English

使用javafxpackager进行非JavaFX2应用程序

[英]Using javafxpackager for non-JavaFX2 application

I have a Java application consisting of several prebuild JAR files and I need to deploy them for different platforms. 我有一个由几个预构建JAR文件组成的Java应用程序,我需要将它们部署到不同的平台。 I recently discovered javafxpackager which is able to create native installers/binaries for Windows, Mac and Linux for a JavaFX2 apps. 我最近发现了javafxpackager ,它能够为Windows,Mac和Linux为JavaFX2应用程序创建本机安装程序/二进制文件。 Since my app is prebuild and doesn't use JavaFX2 it I didn't get the packager to work with my app. 由于我的应用程序是预构建的并且不使用JavaFX2,因此我没有得到打包器来使用我的应用程序。

Does anyone have some experience with this and can help? 有没有人有这方面的经验,可以帮助吗? Or is there another tool which provides the functionality of javafxpackager for non-JavaFX2 applications? 或者是否有另一个工具为非JavaFX2应用程序提供javafxpackager的功能?

You can do this. 你可以这样做。

  1. Build your app into jars as you are currently doing. 正如您目前所做的那样,将您的应用程序构建到jar中。
  2. Run the javafxpackager with the -createjar switch to create a new jar based on your existing jar. 使用-createjar开关运行javafxpackager,根据现有jar创建一个新jar。 The new jar will include manifest entries which allow you to run the jar using java -jar app.jar . 新jar将包含清单条目,允许您使用java -jar app.jar运行jar。
  3. Run the javafxpackager again with -deploy and -native switches to package the jar and java runtime as a native application with installer (a self-contained application ). 使用-deploy-native开关再次运行javafxpackager,以使用安装程序( 独立应用程序 )将jar和java运行时打包为本机应用程序

The important commands are these: 重要的命令是这些:

echo make an executable jar file
$JAVA_HOME/bin/javafxpackager -createjar -srcdir . -appclass start.HelloWorldSwing -srcfiles HelloWorldSwing.jar -noembedlauncher -outdir . -outfile HelloWorld.jar

echo package the jar and java runtime as a native application with installer
$JAVA_HOME/bin/javafxpackager -deploy -srcdir . -srcfiles HelloWorld.jar -outdir . -outfile HelloWorld -appclass start.HelloWorldSwing -native -name HelloWorld

Here is a complete OS X script you can use to build a java application, create a native application package for it, install the native package and run the installed application. 这是一个完整的OS X脚本,您可以使用它来构建Java应用程序,为其创建本机应用程序包,安装本机程序包并运行已安装的应用程序。 The script uses javafxpackager to create the native application package. 该脚本使用javafxpackager创建本机应用程序包。 The installed application is a Swing application which does not use JavaFX (just to demonstrate that javafxpackager doesn't need to work only with JavaFX code). 安装的应用程序是一个不使用JavaFX的Swing应用程序(仅用于演示javafxpackager不需要仅使用JavaFX代码)。 Also the javafxpackager command in the script makes use of a jar previously created with the jar command to show that javafxpackager does not need to work on raw class files, but can take as input a jar previously built with some other toolchain. 此外,脚本中的javafxpackager命令使用先前使用jar命令创建的jar来显示javafxpackager不需要处理原始类文件,但可以将先前使用其他工具链构建的jar作为输入。

You can create packages for other operating systems and packaging formats, eg Windows Apps and Linux RPM or DEB packages. 您可以为其他操作系统和打包格式创建包,例如Windows Apps和Linux RPM或DEB包。 See the javafxpackager documentation for details of how to customize installs for each OS. 有关如何为每个操作系统自定义安装的详细信息,请参阅javafxpackager文档。 If you use the command line javafxpackager tool, then you will need to create packaging shell scripts for each of your target operating systems. 如果使用命令行javafxpackager工具,则需要为每个目标操作系统创建打包shell脚本。 If you use the javafx ant packaging tasks, then you can use the same packaging ant script across operating systems. 如果使用javafx ant包装任务,则可以跨操作系统使用相同的打包ant脚本。 Look at the source for the javafx samples such as Ensemble or SwingInterop for examples on using the ant packaging tasks to build native bundles. 查看javafx示例源代码,例如Ensemble或SwingInterop,以获取有关使用ant打包任务构建本机包的示例。

To build windows installers you need to install additional freeware software on your machine as outlined in the javafxpackager documentation. 要构建Windows安装程序,您需要在计算机上安装其他免费软件,如javafxpackager文档中所述。 To build rpms you will need the rpmbuild packaging utilities installed on your machine. 要构建rpms,您需要在计算机上安装rpmbuild打包实用程序。 Currently it is not possible to build native packages for all OSes from a single machine (you can only build the native packages which are specific to that machine type). 目前,无法从一台计算机为所有操作系统构建本机程序包(您只能构建特定于该计算机类型的本机程序包)。


Remember that javafxpackager native packages are just one of many Java application deployment options. 请记住,javafxpackager本机包只是众多Java应用程序部署选项之一。 Others include webstart, executable jar files, 3rd party packaging options and browser embedded applications. 其他包括webstart,可执行jar文件,第三方打包选项和浏览器嵌入式应用程序。 Choose the option which is most appropriate to your application, users, development skill and complexity comfort level. 选择最适合您的应用,用户,开发技能和复杂性舒适度的选项。


An alternate toolchain I have used in the past with excellent success for native packages of unix software (especially for server side applications for enterprises), is maven with the rpm maven plugin builds created using jenkins deploying to a nexus repository with the nexus yum plugin . 另一种工具链我已经在过去使用的Unix软件(特别是对企业服务器端应用程序)的本地软件包优秀的成功,是Maven的转速Maven插件构建使用创建詹金斯部署到一个关系与存储库关系的yum插件 This toolchain allows you to go from code checkin to a set of deployable packages with yum dependency management. 此工具链允许您从代码签入到具有yum依赖关系管理的一组可部署包。 This alternate toolset does require a bit of sophistication to use though and doesn't cover the range of platforms that javafxpackager does. 这个替代工具集确实需要使用一些复杂功能,并不包括javafxpackager所做的平台范围。

I have a working JavaFX 2 app and I use JavaFX Ant Tasks ( http://docs.oracle.com/javafx/2/deployment/javafx_ant_task_reference.htm#CIADCBJG ) to create an application bundle for Mac OS X. I know that JavaFX Ant Tasks isn't exactly the same as JavaFX Packager tool, but they're quite similar in terms of the functionality they provide. 我有一个有效的JavaFX 2应用程序,我使用JavaFX Ant Tasks( http://docs.oracle.com/javafx/2/deployment/javafx_ant_task_reference.htm#CIADCBJG )为Mac OS X创建应用程序包。我知道JavaFX Ant Tasks与JavaFX Packager工具并不完全相同,但它们在提供的功能方面非常相似。

I changed the main application class of my JavaFX 2 app to not use any JavaFX stuff and just pop up a Window using AWT. 我将JavaFX 2应用程序的主应用程序类更改为不使用任何JavaFX内容,只使用AWT弹出一个Window。

import java.awt.*;
public class MainApplication {
    public static void main(String [] args) {
        Frame f = new Frame("Example 1");
        f.show();
    }
}

I then run the Ant build script (unaltered) again to create a new application bundle. 然后我再次运行Ant构建脚本(未更改)以创建新的应用程序包。 The new application bundle can be launched on Mac without a problem. 可以在Mac上启动新的应用程序包而不会出现问题。 So I think you might be able to use javafxpackager for non-JavaFX2 apps, at least Java AWT-based apps. 所以我认为你可以将javafxpackager用于非JavaFX2应用程序,至少是基于Java AWT的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM