没有-cp选项,jdk1.7的javac无法找到javafx jar [英] jdk1.7's javac can't find javafx jar without -cp option

查看:74
本文介绍了没有-cp选项,jdk1.7的javac无法找到javafx jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在该网站和其他地方阅读了几个问题,这些问题表明在安装Oracle JDK7时,不必正确地安装JDK时,就不必指定jfxrt.jar的类路径.不幸的是,我的安装似乎不正确,但是我无法弄清楚出了什么问题.

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.

我为我的Red Hat Enterprise Linux 6.2 Server使用了正确的RPM,并且当我将jfxrt.jar添加到外部Jars中时,便能够在Eclipse中构建JavaFX应用程序.但是,当尝试从命令行编译并运行时,除非我为javac和java指定-cp选项,否则它将找不到JavaFX类.该服务器最初使用的是openjdk-1.6,但我使用了替代方法来配置javac和java使其指向新安装的JDK.除此问题外,看起来一切正常.

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.

我发现在尝试运行JavaFX Exporter时,同样的问题困扰着我.我试图导出一个在Eclipse中运行良好的项目.但是尝试运行时找不到JavaFX类.而且我还没有弄清楚如何告诉出口商jfxrt.jar文件的位置.

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.

作为参考,jfxrt.jar位于我的系统上的/usr/java/jdk1.7.0_21/jre/lib/jfxtr.jar中.

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

推荐答案

在安装Oracle JDK7时,正确安装JDK时,不必指定jfxrt.jar的类路径.

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

那是不正确的.

如果要在Java 7(u21)中编译并运行JavaFX应用程序,并且没有使用

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.

有关设置示例,请参见使用JavaFX 2.0编译代码(使用命令行) JavaFX类路径,用于从命令行编译(使用javac)和运行(使用java)JavaFX 2应用程序.

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.

某些IDE或IDE扩展知道这一点,并将自动将jfxrt.jar添加到您的类路径中(例如e(fx)clipse插件或NetBeans JavaFX项目类型).

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).

某些第三方工具,例如 JavaFX Maven插件 JavaFX Gradle插件还将JavaFX应用程序打包,因此您无需将jfxrt.jar添加到您的类路径中.

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.

对于Eclipse开发,建议使用 e(fx)clipse插件,因为它可以解决类路径问题(以及为JavaFX开发人员提供其他有用的功能).

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).

对于 Java 8,jfxrt.jar已启用默认的类路径,因此您无需显式设置类路径即可将JavaFX与该Java版本的工具诸如javac.exe或java.exe一起使用.

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.

这篇关于没有-cp选项,jdk1.7的javac无法找到javafx jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆