简体   繁体   English

我有不同版本的javac和java。 我正在尝试在终端上运行.java文件。 但是它可以在日食中工作

[英]I have different versions of javac and java. I'm trying to run my .java file on terminal. But it works in eclipse

How to resolve this? 如何解决呢? I can compile it but I can't run it. 我可以编译它,但不能运行它。 I have different versions of javac and java . 我有不同版本的javacjava I'm trying to run my .java file on terminal. 我正在尝试在终端上运行.java文件。 But it works in eclipse. 但是它可以在日食中工作。 I know that version affects this. 我知道该版本会影响到这一点。 How to upgrade javac ? 如何升级javac Will it affect my eclipse if I do so? 如果这样做会影响我的日食吗? Thanks. 谢谢。 ;) ;)

[clemjon@localhost ~]$ javac -version

javac 1.6.0_20


[clemjon@localhost ~]$ java -version

java version "1.6.0_21"

Java(TM) SE Runtime Environment (build 1.6.0_21-b06) Java HotSpot(TM) Server VM (build 17.0-b16, mixed mode) Java™SE运行时环境(内部版本1.6.0_21-b06)Java HotSpot™服务器VM(内部版本17.0-b16,混合模式)

Check which JRE eclipse is using: 检查使用哪个JRE eclipse:

Window->Preferences->Java->JREs Right click the selected one and Edit . Window->Preferences->Java->JREs右键单击选定的一个,然后单击Edit
The JRE home path should be there. JRE主目录路径应该在那里。 Add that path to your path environment variable (instead of the one that is already there) and that should do the trick for you. 将该路径添加到您的path环境变量(而不是已经存在的环境变量)中,这将为您解决问题。

You can also set which JDK version you want Eclipse to compile to: 您还可以设置希望Eclipse编译到的JDK版本:
Window->Preferences->Java->Compiler

My best advice would be to keep track of all the installed JDK's and JRE's. 我最好的建议是跟踪所有已安装的JDK和JRE。

Choose the ones you want to use by default and add those to your JAVA_HOME and Path environment variables; 选择默认情况下要使用的变量,并将其添加到JAVA_HOMEPath环境变量中; Then setup your Eclipse to the same values using the steps above. 然后使用上述步骤将Eclipse设置为相同的值。

Then if for a particular project you need to use a specific JRE, right click on that project and then go to BuildPath -> Libraries -> JRE Library -> Edit and pick you JRE. 然后,如果对于特定项目,您需要使用特定的JRE,请右键单击该项目,然后转到BuildPath > Libraries -> JRE Library -> Edit并选择您的JRE。

Disclaimer: I'm not on my dev machine right now so the names may be approximate. 免责声明:我现在不在我的开发机器上,因此名称可能是近似的。 :) :)

This is not an issue to do with different versions of javac and java . 这与使用不同版本的javacjava无关。 The problem here is that you are attempting to run a class file whose fully-qualified name ( com.pl.casestudy.First ) doesn't match the class name you passed to java ( First ). 这里的问题是,您正在尝试运行其完全限定名称( com.pl.casestudy.First )与传递给javaFirst )的类名称不匹配的类文件。 You would get the same error if you had the same versions of javac and java . 如果您具有相同版本的javacjava则会得到相同的错误。

If you have a class whose name is com.pl.casestudy.First , Java will look for it in a file with name com/pl/casestudy/First.class (Windows users feel free to reverse the direction of the slashes.) So you will need to run your First class from the directory that contains the com subdirectory. 如果您有一个名称为com.pl.casestudy.First的类,则Java会在名称为com/pl/casestudy/First.class的文件中查找它(Windows用户可以随意反斜杠的方向。)您将需要从包含com子目录的目录中运行First类。 I can see from the shell prompt in your stacktrace that you have a directory named casestudy , I'll assume that the com and pl parent directories also exist. 我可以从堆栈跟踪中的shell提示中看到,您有一个名为casestudy的目录,我假设compl父目录也存在。 Eclipse has probably created them for you. Eclipse可能已经为您创建了它们。

Try cd ing out to the directory that contains com , compiling using 尝试cd出包含com的目录,使用进行编译

javac com/pl/casestudy/First.java

and running using 并使用

java com.pl.casestudy.First

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试使用Java更新oracle数据库中的密码。 难道我做错了什么? - I'm trying to update my password in oracle database using Java. Am I doing something wrong? 我正在尝试将我的JAVA_HOME路径设置为使用我的javac.exe吗? - I'm trying to set my JAVA_HOME path to use my javac.exe? 从Java执行时,MYSQL命令给出错误。 相同的命令在Linux Terminal上可以正常工作。 可能是什么原因? - MYSQL command gives error while being executed from java. Same command works fine on Linux Terminal. What can be the reason? 为什么我得到不同的Java版本 - Why I'm getting different java versions 数独-Java。 我正在尝试查看我的行是否完整。 它不能重复数字 - Sudoku - java. I am trying to see if my row is complete or not. it cannot have a number repeated javac 和 java 的不同环境(版本) - different environments (versions) for javac and java 我正在尝试在Java中读取csv文件。 下面是我的代码 - I am trying to read a csv file in java. Below is my code 我正在尝试从 IntelliJ 的终端运行一个 java 类,但它提出了“java.lang.UnsupportedClassVersionError” - I'm trying to run a java class from the terminal in IntelliJ but it is coming up with "java.lang.UnsupportedClassVersionError" 尝试使用在新文件的其他.java文件中已经声明的其他变量 - Trying to use a different variable that I have already declared in a different .java file in my new file 尽管使用 JAVA 的顺序不同,但检查两个 arrays 是否相等的方法。 我收到有关我的退货声明的错误 - Method to check if two arrays are equal despite different order using JAVA. I'm getting errors about my return statement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM