Intellij Javafx artifact - how do you make it?
Asked Answered
B

2

8

I've been trying all day to turn my javafx application into a jar file. I'm using Java 1.7 update 7.

Oracle has some information, but it just seems scattered all over the place. Intellij is almost doing the job, but I get the following error:

java.lang.NoClassDefFoundError: javafx/application/Application

Which seems to say that I need to tell java where the jfxrt.jar is... If I add this jar to my classpath info for the manifest build in intellij - ctrl+shift+alt+s -> Artifacts -> Output Layout tab -> Class Path, then I get another error:

 Could not find or load main class com.downloadpinterest.code.Main

It seems strange to have to include jfxrt.jar in my class path though...

I've tried to create an ant script as well, but I feel like IntelliJ is 90% of the way there - and I just need a bit of help to figure out why I need to include jfxrt.jar, and why my Main class isn't being found (I'm guessing I need to add it to the classpath somehow?).

Could anyone clue me up as to what is happening? I had a basic gui before which worked fine, but JavaFX seems to be making life complicated!

Blend answered 2/9, 2012 at 15:35 Comment(0)
C
4

Your assumption is correct, you need to add JavaFX to the classpath.
It is located in [JDK]/jre/lib/jfxrt.jar.

To provide JavaFX at runtime, you can bundle it with your application, illustrated in this Oracle guide or make Java 7 Update 6 a requirement for your app, then add [JAVA_HOME]/lib/jfxrt.jar to the classpath at the application's earliest convenience.

The first option means more work for you, but makes absolutely sure that all users have the same version of the library - and you can bundle the JRE as well, while you are at it. The second version doesn't offer this certainty, but is easier to realize.

As a variant to the second option - if bundling the JRE is actually possible for you - , you can also just bundle it in your distribution and then include a shell-scripts/batch-file/executable-wrapper to make your program use it. That way, you get all the certainty from option I with only a moderate boost in difficulty from option II.

Cultch answered 3/9, 2012 at 9:40 Comment(2)
I noticed when I do this Intellij simply adds a line in the jar manifest which has the classpath (it doesn't bundle jfxrt in my jar). This seems like it'll be an issue when others download my program and try to use it - i.e. some people have macs, some linux, some windows, and the path the jfxrt.jar will be different for different people. Do you know anyway to solve this problem?Blend
Thanks, I've asked oracle if there's a full ant example anywhere as I only managed to get so far creating the ant script. I'll post up one if I find one or manage to create one!Blend
C
4

I had the same problem. But I found this blog post: Packaging JavaFX 2 Applications in IntelliJ IDEA 12.1 that shows how to do it in Intellij 12.1

Apparently IntelliJ has the capability to produce an special "JavaFX Application" artifact. It automatically bundles everything it needs within your jar-file.

Claiborne answered 30/7, 2013 at 9:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.