I have created an app using JavaFX 2.1 and wish to export it to be tested. This is the first "real" application I've made, so I have never done this before. In Windows 7 with eclipse I export a runnable jar, click on it, and nothing happens. Can someone tell me why this might be?
Information on Packaging
The app below was packaged using the command line javafxpackager tool. JavaFX also provides ant tasks for packaging. I believe you could create an ant script for packaging and run it's tasks from inside Eclipse.
The e(fx)clipse plugin provides integrated JavaFX packaging functionality by wrapping the JavaFX ant tasks. When developing JavaFX applications with Eclipse, use of e(fx)clipse is highly recommended.
Verifying your JavaFX Packaging
Extract the jar files from the jar (jar xf <jarfile>).
Look at the extracted manifest (META-INF\MANIFEST.MF).
If the main class in the manifest is not com/javafx/main/Main then you have packaged the app wrong.
C:\dev\javafx\willow\dist>jar xf willow.jar
C:\dev\javafx\willow\dist>type MANIFEST.MF
Manifest-Version: 1.0
JavaFX-Version: 2.1
JavaFX-Application-Class: org.jewelsea.willow.Willow
JavaFX-Class-Path: lib\image4j.jar lib\PDFRenderer-0.9.1.jar
Created-By: JavaFX Packager
Main-Class: com/javafx/main/Main
C:\dev\javafx\willow\dist>java -jar willow.jar
For your manifest the JavaFX-Application-Class entry will vary and the JavaFX-Class-Path attribute is probably not needed.
The example jar I used can then be run from the command line using java -jar <jarfile>.
Like mentioned by the jewelsea e(fx)clipse provides you an export wizard which uses the ant tasks provided by JavaFX. You can find a step by step tutorial at https://wiki.eclipse.org/Efxclipse/Tutorials/Tutorial1
Related
I have completed my JavaFX application within gradle build system, and it is working fine in all way. Now I want to export as a .EXE file for standalone software distribution, I tried much more tricks but no gain. If some one can help me out to wrap my project in a software setup, It would be grateful.
Follow these steps to export your JavaFX project into executable Jar
Goto> Project Structure
Goto>>Artifacts
Click "+">> To add new artifact
It will shows a dropdownlist
Select>>Jar>>From module with dependencies
You will see a nested window as shown
Select Main class of your project
Check In the Option " Copy to output directory.." >>Ok
Goto>> Menu-bar>>Build>>Build Artifacts
Select>> your Project.jar>> Build
This will create executable jar file in your project source folder
Locate your jar file in path project\out\artifacts..
Now you can run this jar file simple cmd commad or with batch file
Cmd Command>> Java -jar project.jar
Using batch file>> make .bat file name it "RUN" and write these commands inside
Specify the Java Runtime path and "Javafx Sdk path" along with VM
options & Project Jar
Run your standalone application .. Enjoy ;)
Creating an installer for the desktop platforms (Windows, macOS, Linux) has become easy these days. The tool of choice is jpackage which started to be shipped with JDK 14. It can either be used on the command line on the finished project or you can use a Gradle plugin (https://github.com/beryx/badass-jlink-plugin). If your project is not modularized you could follow this tutorial https://github.com/dlemmermann/JPackageScriptFX which also uses jpackage but together with Maven and some other tools from the JDK. The Maven part could easily be rewritten to Gradle, if needed.
I have a libGDX core and desktop projects in Eclipse. I have put JRuby complete JAR in the core project's build path. If you run the desktop project, it works.
But when you export the desktop project as a runnable jar, the scripting engine returns null because it can't find JRuby. But Jruby is in the build path of the core project!
I tried adding Jruby to the build path of the desktop project, but the same happens. What do I do?
When you export a Runnable JAR file. Don't forget to check:
Package required libraries into generated JAR.
I am trying to build my application jar (non executable jar) with all it's dependenices jar files also to unpack.
Simply to explain my issue, in eclipse, to export runnable/executable jar, there is an option
"Extract required libraries into generated Jar"
Please help me the same option for non-runnable jar also.
Thanks
No there isn't.
Just as background: Packaging dependencies within a JAR file (sometimes called a fat jar or app jar) is not a native Java mechanism but is grafted on using custom ClassLoaders or start scripts packaged in the JAR.
If you create a runnable JAR file with Eclipse it uses a wrapper to run your application which can read the packaged libraries. You can see this if you open the exported JAR file and look at it's Manifest:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ [removed]
Class-Path: .
Rsrc-Main-Class: com.example.Test
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
The JarRsrcLoader sits between your applications Main-Class and the Java Runtime and can then load the packaged dependencies before executing your code. In a library there is no such hook that Eclipse can hook into since the loading is done by someone using your library and you can't control the loading process.
There are mechanisms to combine JAR files into a single one by unpacking the dependencies and then repackaging them into your JAR. Look here for example: How to combine two Jar files
Note though that by repackaging a 3rd party JAR you might run into issues with signed classes or conflicting Metadata.
If you want to publish a library and/or manage dependencies properly I recommend looking into build systems like Maven (http://maven.apache.org/) or Gradle (http://www.gradle.org/). I personally much prefer Gradle.
Edit: This project seems promising: https://github.com/puniverse/capsule
Use Capsule. It does everything you want including set JVM configuration right in the manifest.
With capsule you have the option of packing all of your JARs and native libs right into the capsule JAR, or you can specify your Maven dependencies in the Manifest, and let them be downloaded the first time the capsule is launched.
I develop Java code using Eclipse. When I want a runnable jar I point and click in the GUI like this:
File->Export->Runnable Jar -> Launch Configuration (select MainTest) --LibraryHandling (extract required libraries into generated JAR)
I want to do this automatically, how can I do this in bash?
Depending on what is in your project and what dependencies you have, this could be pretty complex using the command line tools Java provides. The Java tutorial is pretty good in explaining the usage of the related tools that ship with Java to create jars, but I think most people suggest using a build tool like Maven or Gradle for command line builds.
If you're using the jar tool though, the most basic example for the jar tool with a runnable Main class being specified is:
jar cmf existing-manifest jar-file input-file(s)
where existing-manifest would be your manifest file that specifies your main class.
I have a Java project in Eclipse with class MainClass having main method in package :
com.nik.mypackage.
The project also references two external libraries, which I copied in the lib folder in Eclipse and then added to build path using ADD JAR function. The libraries being one.jar and two.jar
This library is in lib folder in eclipse and added to the build path.
I want to create a executable JAR of the application using ant script. So that user can access my application using command:
c:>java -jar MyProject-20111126.jar
I know about the Eclipse plugin which directly exports a java application as runnable JAR. But I want to learn ant and the build process so manually want to create the build.xm.
You have two options from your build.xml. You can either unjar the library jars and then bundle their contents with the code compiled for your application. Or, you can put the library jars on the filesystem and supply a ClassPath entry in the manifest file of the MyProject-2011126.jar file.
If you set the classpath in the manifest remember that the path you supply is relative to the MyProject-2011126.jar.
one alternative:
Instead of having only a jar, you build mutiple jars (your jar + libs) +batch file.
So, your built package can be like this structure:
-/package/bin/app.bat
/package/lib/my.jar
/package/lib/one.jar
/package/lib/two.jar
In app.bat you just have the same as your code
java -jar MyProject-20111126.jar
PS: if you want to start learning built tools, ANT may be a bit tool old. I suggest http://maven.apache.org/
Please try one-jar. It helps to redistribute everything packaged as single jar and comes with ant-task . See Easiest way to merge a release into one JAR file.