12

I've read several questions on this site and elsewhere that indicate that when Oracle JDK7 is installed, it should not be necessary to specify the classpath to jfxrt.jar when the JDK is installed correctly. Unfortunately, my installation does not seem to be correct, but I cannot figure out what is wrong.

I used the correct RPM for my Red Hat Enterprise Linux 6.2 Server and I'm able to build JavaFX apps in Eclipse when I added the jfxrt.jar to the External Jars. But when trying to compile and run from the command line, it does not find JavaFX classes unless I specify the -cp option to javac and java. The server was originally using openjdk-1.6, but I used alternatives to configure javac and java to point to the newly installed JDK. It looks like that is working fine, except for this issue.

I found that the same problem plagued me when trying to run the JavaFX Exporter. I was trying to export a project that runs fine in Eclipse. But it could not find the JavaFX classes when trying to run. And I haven't worked out how to tell the exporter where the jfxrt.jar file is located.

For reference, the jfxrt.jar is located at /usr/java/jdk1.7.0_21/jre/lib/jfxtr.jar on my system.

Sergey Grinev
  • 34,078
  • 10
  • 128
  • 141
kithril
  • 1,183
  • 2
  • 12
  • 22
  • Is the path /usr/java/jdk1.7.0_21/jre/lib/ in the CLASSPATH variable available to your shell? See [this link](http://docs.oracle.com/javase/tutorial/essential/environment/paths.html) for an example (scroll down for Linux specific info). – Mr Moose May 31 '13 at 05:08
  • It was not because comments I had read here said it wasn't necessary. However, it works fine when I add it to my CLASSPATH. – kithril Jun 02 '13 at 01:47

2 Answers2

14

when Oracle JDK7 is installed, it should not be necessary to specify the classpath to jfxrt.jar when the JDK is installed correctly.

That is not true.

If you want to compile and run a JavaFX application in Java 7 (u21) and you are not using the JavaFX packaging tools, you need to add jfxrt.jar to your classpath.

See Compile code using JavaFX 2.0 (using command line) for samples of setting the JavaFX classpath for compiling (with javac) and running (with java) a JavaFX 2 application from the command line.

Some IDEs or IDE extensions are aware of this and will automatically add jfxrt.jar to your classpath (e.g. the e(fx)clipse plugin or the NetBeans JavaFX project type).

Some 3rd party tools such as the JavaFX Maven Plugin or the JavaFX Gradle Plugin also package JavaFX applications so that you don't need to add jfxrt.jar to your classpath.

For Eclipse development, use of the e(fx)clipse plugin is recommended, as it takes care of classpath issues (as well as providing other useful capabilities for JavaFX developers).

For Java 8, jfxrt.jar is on the default classpath, so you don't need to explicitly set your classpath to use JavaFX with tools like javac.exe or java.exe for that Java version.

Community
  • 1
  • 1
jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • Thanks for that. I'll make the adjustments to my classpath now. I suppose even here misinformation can get out and it's good to get it corrected. I did have issues with the JavaFX packaging tools not finding the jar file as well, which is what made me think my install was wrong. But perhaps I need to look more closely at that issue. – kithril Jun 02 '13 at 01:43
  • Regarding your JavaFX packager issue, try running it with `-nocss2bin` to turn off the binary CSS conversion - I think then it doesn't care about the jfxrt.jar location. If you have further issues with the packaging portion, you can log a separate question to get help with that. – jewelsea Jun 02 '13 at 03:33
  • If I ship an Oracle JRE 7 with my application, would it work to move `lib/jfxrt.jar` into `lib/ext/`? – hfs Jan 07 '15 at 09:37
0

OpenJdk7 does not include jfxrt.jar. Use Oracle Jdk7 instead will help.

clasnake
  • 309
  • 2
  • 9