Reputation: 377
I have a Java application consisting of several prebuild JAR files and I need to deploy them for different platforms. I recently discovered javafxpackager
which is able to create native installers/binaries for Windows, Mac and Linux for a JavaFX2 apps. Since my app is prebuild and doesn't use JavaFX2 it I didn't get the packager to work with my app.
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?
Upvotes: 3
Views: 1995
Reputation: 159291
You can do this.
-createjar
switch to create a new jar based on your existing jar. The new jar will include manifest entries which allow you to run the jar using java -jar app.jar
.-deploy
and -native
switches to package the jar and java runtime as a native application with installer (a self-contained application).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. The script uses javafxpackager to create the native application package. 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). 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.
You can create packages for other operating systems and packaging formats, e.g. Windows Apps and Linux RPM or DEB packages. See the javafxpackager documentation for details of how to customize installs for each OS. If you use the command line javafxpackager tool, then you will need to create packaging shell scripts for each of your target operating systems. If you use the javafx ant packaging tasks, then you can use the same packaging ant script across operating systems. 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.
To build windows installers you need to install additional freeware software on your machine as outlined in the javafxpackager documentation. To build rpms you will need the rpmbuild packaging utilities installed on your machine. 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. Others include webstart, executable jar files, 3rd party packaging options and browser embedded applications. 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. This toolchain allows you to go from code checkin to a set of deployable packages with yum dependency management. This alternate toolset does require a bit of sophistication to use though and doesn't cover the range of platforms that javafxpackager does.
Upvotes: 2
Reputation: 1355
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.
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.
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. The new application bundle can be launched on Mac without a problem. So I think you might be able to use javafxpackager for non-JavaFX2 apps, at least Java AWT-based apps.
Upvotes: 1