问题描述
我已经解压缩我的jdk在/ usr / java /.
I have unpacked my jdk in /usr/java/.
,我把CLASSPATH,PATH,JAVA_HOME放入/ etc /
and I put CLASSPATH, PATH, JAVA_HOME into /etc/profile like below.
export JAVA_HOME=/usr/java/jdk1.7.0_21
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
当我在/usr/java/jdk1.0.7_21/bin中编译一些java文件时,
And when I compile some java file in /usr/java/jdk1.0.7_21/bin,
它工作。但是当我在其他文件夹上做同样的事情时,它不会。
it works. But when I am doing same thing on other folder, it doesn't.
它显示NoClassDefFoundError。
It displays NoClassDefFoundError.
所以我通过echo检查了ClASSPATH,PATH,JAVA_HOME。
So I have checked ClASSPATH, PATH, JAVA_HOME via echo.
它显示如下。
[root@localhost a]# echo $JAVA_HOME
/usr/java/jdk1.7.0_21
[root@localhost a]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/guest/bin:/usr/java/jdk1.7.0_21/bin:/usr/java/bin:/usr/java/jdk1.7.0_21/bin
[root@localhost a]# echo $CLASSPATH
/usr/java/jdk1.7.0_21/jre/lib/ext:/usr/java/jdk1.7.0_21/lib/tools.jar
我想在控制台中使用java,我该怎么办?
I want to use java in console, What can I do fir this situation?
提前感谢。
PS。的couse我做了 source / etc / profile
。
PS. of couse I did source /etc/profile
.
============ =====错误,我面对的=======================
=================The Errors what I'm facing with =======================
当我命令java A(我的类名是A)。
when I command java A(My class name is A).
Error: Could not find or load main class A
case命令java -cp / home / guest / workspace / AAA / src / a / A
case I command java -cp /home/guest/workspace/AAA/src/a/ A
Exception in thread "main" java.lang.NoClassDefFoundError: A (wrong name: a/A)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
=====================我的代码的全部内容======= java部分。路径为/usr/guest/workspace/AAA/src/a/A.java
=====================full content of my code======================================java part. path is /usr/guest/workspace/AAA/src/a/A.java
package a;
public class A {
public static void main(String[] args) {
System.out.println("a!\n");
}
}
/ etc /左侧部分是默认值。
/etc/profile part. left part is default.
export JAVA_HOME=/usr/java/jdk1.7.0_21
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
其他部分可能有助于解决。
other parts might be helpful to solve.
-
which java
prints/ usr / java / bin。有符号链接。 - 我的jdk位置是/usr/java/jdk1.7.0_21。 ./bin每个代码都很好。
- 我没有碰/root/.bash_profile。我刚刚编辑了/ etc / profile。
which java
prints "/usr/java/bin". there's symbolic link.- My jdk location is /usr/java/jdk1.7.0_21. inside of ./bin every code works fine.
- I did not touch /root/.bash_profile. I just edited /etc/profile.
感谢您的关注。即使它没有想出来。
Thanks for such interest. even though it does not figured out. your help was great healing to me :D Thanks again.
推荐答案
我在/ home / prasanth中创建了一个名为a的文件夹,然后复制你的代码到一个名为A.java的文件。我从/ home / prasanth中编译为 javac a / A.java
并运行 javac a.A
。我输出为
I created a folder named a in /home/prasanth and copied your code to a file named A.java. I compiled from /home/prasanth as javac a/A.java
and run javac a.A
. I got output as
a!
这篇关于设置JAVA_HOME& CLOSSPATH在CentOS 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!