Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Build a JavaFX Application It's About Time Momma Said

Harry James
Harry James
14,780 Points

[Guide] Export your app!

Awesome! You've got your Pomodoro Timer ready now. How about you share it with your friends and family? Or perhaps you just want an easier way to access it?

You can export your app as a .jar file which allows anyone with the JVM on their system to run your app - there's no need for them to have an IDE or access to your code. Here's how to do it:


Go to File >> Project Structure (Ctrl+Alt+Shift+S) and head over to the Artifacts tab. Here, click the + icon and choose JavaFX Application from module 'Pomodoro':

Next, head over to the Java FX tab. Here, fill in all of the information as follows (You may change the Output directory to whatever you want or leave it on the default):

  • Output directory: This is where you want to save your .jar file to. You may change this to wherever you want - the screenshot above shows my default location.
  • Application class: Where is the Main class located? You can use the ... for easy navigation.
  • Width / Height: We set these defaults in the Main class but we should do so again here.

That's it! Go ahead and click OK now. Now that the initial setup is done, all we need to do is build the application!


Go to Build >> Build Artifacts and a small window will appear. Under the Pomodoro module, select Build. Watch the progress bar on the bottom of IntelliJ - when it is done the application file has been created (They really should add a prompt of some sort to say that, anyhow):

To access it, go to the location you specified under Output directory. If you too left yours at the default, then you can get to this directory by right-clicking on the Pomodoro.jar file under out >> artifacts >> Pomodoro and then choosing Show in Explorer:


Awesome! Hopefully you have a project ready to share. Even if you're not going to share it, this will be super handy so that you can get your Pomodoro Timer up straight away - without the need to open your IDE.

Have fun and if you have any problems with any of this, give me a shout in the Comments and I'll be sure to help you out :)

Travis Avey
Travis Avey
18,876 Points

Wow! Thank you for all this hard work for this guide! I will be sure to use it when I finish this app =)

Thomas Beaudry
Thomas Beaudry
29,084 Points

Thank you for taking the time to go into so much detail and effort, as a fellow student it is greatly appreciated.

Jenny Swift
Jenny Swift
21,999 Points

Great guide. Thank you so much Harry!

Kareem Jeiroudi
Kareem Jeiroudi
14,984 Points

Man, you're great, thanks for adding that to the course material. I was actually about to ask the same thing. I'd like to use this app right now, especially now that it's done, and that I don't need my IDE to run it every time I want to. Again, special thanks to your helpful notes ?!

5 Answers

Harry James
Harry James
14,780 Points

Marking as resolved

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Nice work, Harry! Thanks so much for writing up such a detailed explanation here! :bowtie: :+1:

Awesome guide Harry James! Thanks!

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Also you can take it a step further and make a self contained application if you are feeling brave!

Craig, the IntelliJ IDE 15 EAP includes the ability to create Native Bundles from the JavaFX tab in the Project structure as outlined by Harry James

Now, all we need is an easy way to set app icons and maybe get fancy with a splash screens;)

I am really really curious to know how to do this, that article is pretty techie :( Can you help us with this ? A workshop, or a course if needed would be great :D

Thanks

Tim Strand
Tim Strand
22,458 Points

In the article it mentions that a drawback of Self-Contained applications is that its a download and run user experience. is there a way that we are able to allow the app to be accessed via the internet? it would be nice to have it follow me from pc to pc rather than reinstalling on each of my pcs. PS Thanks so much for the course, getting ready to retake it to soak in more knowledge. Really appreciate your efforts.

Thomas Beaudry
Thomas Beaudry
29,084 Points

Craig Dennis, no way, am not feeling THAT brave !!;)

Chris Perry
Chris Perry
13,807 Points

So I followed this guide and I have my nice little Pomodoro application sitting here. When I try to run it though, it gets blocked by my security settings. After doing some research, the new Java 8 security protocols need all applications to be signed/verified by a trusted source, and apparently a personal application running on my local computer isn't trusted :( Am I missing something or can someone point me in the right direction please? I'd love to be able to use my own programs if that's possible!

Thanks :)

Gi Devs
Gi Devs
12,171 Points

so I built the bundle and I've got an exe but when I run it I get an error saying this "Failed due to exception from the main class"

it still runs fine in the IDE though

Kevin Carl David
Kevin Carl David
10,189 Points

when i make changes on the files, would that take effect on the built program? or do u need to rebuild? thanks :)

Harry James
Harry James
14,780 Points

Hi Kevin,

You would need to rebuild for the changes to be made in the file :)

Hope it helps!