This content has been marked as final. Show 6 replies
Package the Java application as a Jar File use the javafxpackager or javafx ant tasks or netbeans.
After the application is correctly packaged as <app>.jar, run it by either:
1. double clicking on the jar file in Explorer OR
2. by typing java -jar <app>.jar from the command line.
There is no need to put the jfxrt.jar on the classpath - something in the packaging and javafx install allows the jar to find the runtime if the runtime is installed.
The manifest of the properly packaged jar file will be something like:
The above is generated by the packaging scripts - you don't need to create it manually, I just provided it for reference in case you need to troubleshoot.
Manifest-Version: 1.0 JavaFX-Version: 2.0 implementation-vendor: John_Smith implementation-title: JavaFXApplication4 implementation-version: 1.0 JavaFX-Application-Class: org.acme.explosives.HelloCss JavaFX-Class-Path: JavaFX-Fallback-Class: com.javafx.main.NoJavaFXFallback Created-By: JavaFX Packager Main-Class: com/javafx/main/Main
If you want to include your own lib files in your packaging, (and the packaging is done correctly) the manifest will include relative references to the lib files and you just put your lib files in the correct directories relative to your <app>.jar file - note that you don't need to put jfxrt.jar in a relative lib directory as the relative lib file lookup is only for other jars your app relies on.
Here is a script to package the application from the commmand line using javafxpackager Re: How to compile JavaFX 2.0 app with javac.exe from command prompt? but doing it via netbeans or ant is preferable, zonski also put together something to package via maven if you prefer to use that tool.
Edited by: jsmith on Dec 8, 2011 12:21 PM
Added info on relative lib directories.
My situation is a bit more complicated. I've written a Java IDE that runs custom Java code in a player by downloading class files from Google App Engine and dynamically loading them. I have options to kick off the process as a JNLP applet or app, but for the purposes of development and debugging, I need to Runtime.exec() the player.
I hadn't considered it before, but perhaps there's a "javafx.home" property (or some other way to discern it from the runtime)?
prompt> java -cp c:\Program Files\Oracle\JavaFX 2.0 Runtime\lib\jfxrt.jar my.app.Mainyou do not have your application classes on the class path here, do not you?
spawning an embedded launcher class instead of application main is preferable but if you are confident runtime is available and you know all the paths then i'd assume you should be able to run it this way (with my.app.Main having main() method defined too).
You can also have your player to create new URLClassLoader, add javafx and application class path to it, create new thread group with this class loader as context class loader, and load your application class from this class loader and run its main. Then you can run your javafx code in the same process (if desired).
This is pretty much what embedded launcher does anyways (besides checking JavaFX and JRE are installed and handling corner cases).