Anda di halaman 1dari 13

18/07/13

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

edu.makery.ch
How to Make Things.
Search

Navigate

Home Archives Projects About

JavaFX 2 Tutorial Part VII - Deployment With E(fx)clipse


Dec 18th, 2012 Updated Feb 11th, 2013: New instructions for Deployment on Mac OS. Thank you Eskil for providing me with this information! Updated May 22nd, 2013: Updated step 3 and step 4 for e(fx)clipse plugin version 0.8.1.

edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/

1/13

18/07/13

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

I thought Id write one last part of this tutorial series to show how to deploy (i.e. package and publish) the AddressApp. Download example AddressApp as Windows exe installer: AddressApp-0.7.exe. MacOS dmg drag-and-drop installer: AddressApp.dmg - Thank you Eskil for providing this!

Topics in Part VII


Deploying our JavaFX application as Native Package with e(fx)clipse

Other Tutorial Parts


Part I - Scene Builder Part II - Model and TableView Part III - Interacting with the User Part IV - CSS Styling Part V - Storing Data as XML Part VI - Statistics Chart Part VII - Deployment with e(fx)clipse

What is Deployment
Deplyoment is the process of packaging and delivering software to the user. This is a crucial part of software development since its the first contact a user has with our software. Java advertises with the slogan Write Once, Run Anywhere to illustrate the cross-platform benefits of the Java language. Ideally, this means that our Java application can be run on any device equipped with a Java virtual machine (JVM). In the past, the user experience for installing a Java application hasnt always been smooth. If the user didnt have the required Java version on his system, he had to be directed to install it first. This lead to some difficulties, e.g. need for admin rights, compatibility issues between Java versions, etc. Fortunately, JavaFX 2 provides a new deployment option called Native Packaging (also called SelfContained Application Package). A native package is a bundle containing both your application code and the (platform-specific) Java Runtime. The official JavaFX documentation by Oracle contains an extensive guide for all possible JavaFX deployment options. In this post I will show how to create a Native Package with with Eclipse and the e(fx)clipse plugin. My current e(fx)clipse version is 0.1.1.

Create a Native Package


The goal is to create a self-contained application in a single folder on the users computer. Here is how it will look like for our AddressApp (on Windows):
edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/ 2/13

18/07/13

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

The a p pfolder contains our application data and the r u n t i m efolder contains the platform-specific Java runtime. To make it even more comfortable for the user, well provide an installer: A. e x efile installer on windows Ad m g(drag and drop) installer for MacOS. The e(fx)clipse plugin will help us generate the native package and installer.

Step 1 - eclipse.ini
Note: Step 1 might not be necessary with e(fx)clipse 0.8.0 and above. See Tom Schindls comment below (the author of e(fx)clipse). JavaFX uses a tool called Ant to build and package the application. This tool is already included in Eclipse. As Ant depends on the JDK we need to make shure Eclipse itself runs with the JDK (not the JRE). 1. Close Eclipse. 2. Find the folder of your Eclipse installation and open the file e c l i p s e . i n iin a text editor. This file contains Eclipse startup settings. On Mac OS X, eclipse.ini can be found by right-clicking Eclipse.app and selecting Show package contents. The file is located under Contents/MacOS. 3. After the line o p e n F i l eadd v mand then specify your jdk installation directory. The end of the file should now look like this: eclipse.ini
1o p e n F i l e 2v m 3C : \ P r o g r a mF i l e s \ J a v a \ j d k 1 . 7 . 0 _ 0 9 \ b i n \ j a v a w . e x e 4v m a r g s 5X m s 4 0 m 6X m x 5 1 2 m

Mac OS: For Mac OS, path can be something like /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/bin/java (In my version the javaw.exe does not exist but I specified java instead which seemed no problem)

Step 2 - Installer Icons


We would like to have some nice icons for our installer:
edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/ 3/13

18/07/13

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

1. Download AddressApp.ico, AddressApp-setup-icon.bmp and AddressApp.icns. 2. Copy the three icons to the project root of your AddressApp project in Eclipse.

Step 3 - Edit build.fxbuild


The file b u i l d . f x b u i l dis used by e(fx)clipse to generate a file that will be used by the Ant build tool. If you dont have a b u i l d . f x b u i l dfile, create a new Java FX Project in Eclipse and copy the generated file. 1. Open b u i l d . f x b u i l dfrom your project root. 2. Fill out all the fields containing a star. For MacOS: Do not use spaces in Application title as this seems to cause a problem.

edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/

4/13

18/07/13

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

3. As Packaging Format choose e x efor Windows, d m gfor MacOS, and r p mfor Linux. 4. Click on the link G e n e r a t ea n tb u i l d . x m lo n l y(found on the right side). 5. Verify that a new b u i l dfolder and a file b u i l d . x m lis created.

Step 4 - Edit build.xml to include icons


E(fx)clipse has generated a file b u i l d / b u i l d . x m lwhich is ready to be executed by Ant. Our installer icons and resource icons just wont work. If you dont want icons you may skip this step. As e(fx)clipse cant be told (yet?) to include additional resources like our r e s o u r c e sfolder and the few installer icons weve added above, we have to manually edit the b u i l d . x m l : Open b u i l d . x m land find the path f x a n t . Add one line for the $ { b a s e d i r }(will make our installer icons available): build.xml
1< p a t hi d = " f x a n t " >
edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/ 5/13

18/07/13

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

2 < f i l e l i s t > 3 < f i l en a m e = " $ { j a v a . h o m e } \ . . \ l i b \ a n t j a v a f x . j a r " / > 4 < f i l en a m e = " $ { j a v a . h o m e } \ l i b \ j f x r t . j a r " / > 5 < f i l en a m e = " $ { b a s e d i r } " / > 6 < / f i l e l i s t > 7< / p a t h >

Find the following block further down in the file:


1 2 3 4 < f x : r e s o u r c e si d = " a p p R e s " > < f x : f i l e s e td i r = " d i s t "i n c l u d e s = " A d d r e s s A p p . j a r " / > < f x : f i l e s e td i r = " d i s t "i n c l u d e s = " l i b s / * " / > < / f x : r e s o u r c e s >

Replace the four lines obove with the following code:


1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 < m k d i rd i r = " d i s t / r e s o u r c e s "/ > < c o p yt o d i r = " d i s t / r e s o u r c e s "> < f i l e s e td i r = " . . / r e s o u r c e s "/ > < / c o p y > < m k d i rd i r = " p a c k a g e "/ > < ! -I c o n so n l yf o rW i n d o w s> < m k d i rd i r = " p a c k a g e / w i n d o w s "/ > < c o p yt o d i r = " p a c k a g e / w i n d o w s " > < f i l e s e td i r = " . . " > < i n c l u d en a m e = " A d d r e s s A p p . i c o "/ > < i n c l u d en a m e = " A d d r e s s A p p s e t u p i c o n . b m p "/ > < / f i l e s e t > < / c o p y > < ! -I c o n so n l yf o rM a c O S> < m k d i rd i r = " p a c k a g e / m a c o s x "/ > < c o p yt o d i r = " p a c k a g e / m a c o s x " > < f i l e s e td i r = " . . " > < i n c l u d en a m e = " A d d r e s s A p p . i c n s "/ > < / f i l e s e t > < / c o p y > < f x : r e s o u r c e si d = " a p p R e s " > < f x : f i l e s e td i r = " d i s t "i n c l u d e s = " A d d r e s s A p p . j a r " / > < f x : f i l e s e td i r = " d i s t "i n c l u d e s = " l i b s / * " / > < f x : f i l e s e td i r = " d i s t "i n c l u d e s = " r e s o u r c e s / * * " / > < / f x : r e s o u r c e s >

Step 5 (WINDOWS) - Windows exe Installer

edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/

6/13

18/07/13

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

With Inno Setup we can create a Windows Installer of our application as a single . e x efile. The resulting . e x ewill perform a user level installation (no admin permissions required). A shortcut will be created (menu or desktop) 1. Download Inno Setup 5 or later. Install Inno Setup on your computer. Our Ant script will use it to automatically generate the installer. 2. Tell Windows about the installation path to Inno Setup (e.g. C : \ P r o g r a mF i l e s( x 8 6 ) \ I n n o S e t u p5 ): Add it to the P a t hvariable in your windows environment variables. If you dont know where to find it, read How to set the path and environment variables in Windows.

Step 5 (MAC) - MacOS dmg Installer

To create a Mac OS d m gdrag-and-drop installer, no additional tool is required. Note: For the installer image to work it must have exactly the same name as the application.

Step 5 (LINUX etc.) - Linux rpm Installer


For other packaging options (m s ifor windows, r p mfor Linux) see this native packaging blog post or this oracle documentation.

Step 6 - Run build.xml


As a final step, we run the b u i l d . x m lwith Ant: Right-click on the b u i l d . x m lfile | Run As | Ant Build.

edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/

7/13

18/07/13

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

The building will take a while (about 1 minute on my computer). If everything was successful, you should find the native bundle in the folder b u i l d / d e p l o y / b u n d l e s : Windows: The file A d d r e s s A p p 1 . 0 . e x ecan be used as a single file to install the application. This installer will copy the bundle to C : / U s e r s / [ y o u r n a m e ] / A p p D a t a / L o c a l / A d d r e s s A p p . Hint: You could also use the subfolder b u i l d / d e p l o y / b u n d l e s / A d d r e s s A p pto deploy the application as a . z i pfile.

Whats Next?
I hope this tutorial was a help for you to get started with JavaFX and youll be able to write your own JavaFX project from here. I might add some further JavaFX blog posts outside of this tutorial series, well see I appreciate any feedback. Feel free to write comments if you have any suggestions or if something was unclear.

Download Source
Source of Tutorial Part VII as Eclipse Project. Posted by Marco Jakob Updated May 22nd, 2013 English, JavaFX
Tweet 4 0

Creating PDFs in Java New Java and JavaFX Learn Pages

Comments
31 comments Leave a message...
Best Community Albert55

Share

3 months ago

Please I need your help. I am using a H2 embedded database in my javaFX application. the database file is in my src folder in a java project under eclipse . How can I deploy it with my application. I used the method you described it but It didn't work. Thanks
5

Reply

Share
a month ago

Marc Van Belleghem

hello marco,
edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/ 8/13

18/07/13

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

Your tutorial is realy good but i have a little problem. It didn't work as you explained. I had to add a classpath in my build xml. <property location="C:\Program Files\Java\jdk1.7.0_10\jre\lib\jfxrt.jar" name="classpath"> because he didn't found the jfxrt.jar. Now your adressapp makes a native bundle as discribed. When i install it on my pc i get an error jvm.dll not found. Is this problem caused by my adation? Now i would like to know which jvm he doesn't find. I have a jvm.dll in 5 different jdk directories en 3 jvm.dll in my jre directories.</property>
Reply Share
Mod

Marco Jakob

> Marc Van Belleghem


Share

a month ago

I think it should probably find your jdk without the change you made. So try removing your property location and make sure that ant finds your jdk.
1

Reply

Marc Van Belleghem

> Marco Jakob

a month ago


rohini

Finally I found the solution for my problem. Because I am a newbie I didn't know that in eclipse I had to adapt the External Tools configurations. (Eclipse Run External Tool External Tool Configurator ) Under the tab JRE You can change this. There i added a seperate JRE as standard machine that points to my last JDK. Perhaps this is some information who may be usefull for other newbies.
Reply Share

a month ago

i have created build.xml. however its not taking external dependency jars for my project. How can i add those. Thanks in advance!
Reply Share

Carlos Esteban Gottardi

a month ago

Very nice tutorial Marco, it help me a lot!!!! but it would be very nice if you update it with some kind of REST backend communication and not XML like Spring, roo, grails or something like that to persist the data to a database. Sorry if my english is bad :(. Thanks in advance.
Reply

Share

craigTheBrit

2 months ago

I'm opening some assets in my application using [class].getResourceAsStream([absolute path to asset]). This works fine when the app runs from fxclipse, but the method always returns null when being run in the jar, and hence the app fails to open. There's something in the back of my mind about having to add directory path listings to the JAR file (maybe manifest?) but I can't think how to do this in the ant task's build.xml. Any ideas?
Reply Share
9/13

edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/

18/07/13

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

Marco Jakob

Mod

> craigTheBrit
Share

2 months ago

Does this help? http://stackoverflow.com/quest...


Reply

craigTheBrit

> Marco Jakob

2 months ago


Rossco

Yes - stackoverflow comes to the rescue again! The solution for me was to use getClassLoader().getResourceAsStream(...) and provide the full path to the asset in the form "com/...", with no preceding slash. Thanks for the tutorial!
Reply Share

2 months ago

after following all the steps, when I try to run the AddressApp.exe that's generated I get: "The version of this file is not compatible with the version of Windows you're running. Check your computer's system information to whether you need an x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher." I even did step 1, specifying the path to the jdk in the eclipse.ini file

what is up with this? :)


Reply Share
Mod

Marco Jakob

> Rossco
Share

2 months ago

Make sure you have all ingredients in either 32bit or 64bit. That means if you want a 32bit version you should have a 32bit JDK (specified in eclipse.ini) and a 32bit Eclipse.
Reply Rossco

> Marco Jakob

2 months ago

everything checks out: 32bit JDK with 32bit eclipse on 32bit Windows 7 Like "Carlos Henrique Latanza" I'm also using a later version of e(fx)clipse than you are, which does not have a "native package" option (version: 0.8.1.2); perhaps this is why I've experienced issues. What version of e(fx)clipse are you using? I'll try to go with that and see if it makes a difference.
Reply Share
Mod

Marco Jakob

> Rossco

2 months ago


rossco
edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/

I've updated the blog post for e(fx)clipse version 0.8.1. There is no 'native pack option' any more but instead you need to choose the 'Packaging Format'.
Reply Share

> Rossco

2 months ago
10/13

18/07/13

rossco

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch Rossco 2 months ago

>


rossco

you're using "in the current version 0.1.1" ?


Reply
Mod

Share

Marco Jakob

> rossco
Share

2 months ago

yep, 0.1.1 is the last version I tried. Let's see if I can reproduce your issue.
Reply

> rossco

2 months ago

also: just noticed that nothing is being generated in the "dist/resources" folder.

why might this be?


Reply Share

Rossco

> rossco

2 months ago

"you need to choose the 'Packaging Format'." yeah, that was it. all problems solved. works 100% would be awesome if the user could be able to select default app location download upon installation (ex. C:\Program Files, C:\Desktop, etc.), but this is a very nice start.


Carlos Henrique Latanza

thanks for the wicked awesome tutorials, and for the incredible help!
Reply
Mod

Share

Marco Jakob

> Rossco
Share

2 months ago

Glad I could help.


Reply

Rossco

> Rossco
Reply

2 months ago

I mean: if the user could be able to select default app download location* upon installation
Share

2 months ago

im stuck at step 3,i dont have the native pack option on deploy tab, can you help me please?
Reply Share
Mod

Marco Jakob

> Carlos Henrique Latanza


Share

2 months ago

edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/

I've updated the blog post for e(fx)clipse version 0.8.1. There is no 'native pack option' any more but instead you need to choose the 'Packaging Format'.
Reply
11/13

18/07/13


Pavel Degtev

Reply

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

Share

Marco Jakob

Mod

> Carlos Henrique Latanza


Share

2 months ago

Maybe there is a new version of e(fx)clipse where things are a little different. I don't have a new version installed right now.
Reply

4 months ago

Buttons apear clipped Ne.... Ed..... Ca..... if run exe or from instal. But looked correct if run from eclipse. What wrong ?
Reply

Share
4 months ago

Pavel Degtev

Spasibo! Ochen tolkovoe, poleznoe,celnoe rukovodstvo. Thank you, very good, usefull, "fullended"( : ) ) tutorial.

If any other on JavaFX - you will find time and effort for - will be very good. ; )
Reply

Share

whatOne

CO
Reply

6 months ago

Share

Thank you!

Tom Schindl

7 months ago

With the upcoming release 0.2.0 the preconfiguration of the JDK is not needed anymore. If the ant launch generator detects that it runs only with a JRE it wil pop up a dialog asking for a JDK.

Support for deployment customization as shown is scheduled for the next release after 0.2.0
Reply Share
Mod

Marco Jakob

> Tom Schindl

7 months ago

Wow, great! These are exactly the two important things that are missing. Looking forward to the next release!


Ralph

Thank you for your awesome Eclipse plugin, Tom!


Reply Share

7 months ago

I'm on linux (debian-like). The build only work after i change the location of ant-javafx.jar and jfxrt.jar to absolute path. For some reason it did not found the location of "java.home". After the build was complete, the .deb and .rpm packages was created. I tried to run it through "AddressApp" under the "build" dir, but got the error "jvm.dll is not found [...]
edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/ 12/13

18/07/13

JavaFX 2 Tutorial Part VII - Deployment with e(fx)clipse - edu.makery.ch

Failed to lunch JVM".


Reply Share
Mod

Marco Jakob

> Ralph
Share

7 months ago

I've had the exact same error with Windows before. Starting Eclipse with -vm C:\Program Files\Java\jdk1.7.0_09\bin\javaw.exe solved it for me (see Step 1 above).
Reply Ralph

> Marco Jakob

7 months ago


Projects

Find it another way to successfully compile: add ant-javafx.jar and jfxrt.jar at the global entries classpath on Ant runtime configuration at eclipse. However, the "jvm.dll is not found" still persist when the application is executed. Strange is, the build process copy libs to deploy location instead of using existing libraries at the O.S. Is this normal?
Reply Share

Learn Programming Learn JavaFX Dart HTML5 Drag and Drop Dart Event Bus

Categories
All (24) Dart (1) Deutsch (1) English (23) Java (6) JavaFX (16) Copyright 2013 - Marco Jakob - Powered by Octopress - Icons by glyphicons and icondrawer

edu.makery.ch/blog/2012/12/18/javafx-tutorial-addressapp-7/

13/13

Anda mungkin juga menyukai