Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jdk1.7's javac can't find javafx jar without -cp option

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.

like image 941
kithril Avatar asked May 31 '13 04:05

kithril


1 Answers

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.

like image 103
jewelsea Avatar answered Oct 15 '22 14:10

jewelsea