我想恢复我的MAc os 10.7.4的默认java CLASSPATH

时间:2012-06-13 20:16:36

标签: java macos classpath

我已多次询问www.google.com,但我似乎无法弄清楚如何将其恢复为默认值。

我现在无法简单地编译和运行java文件..

romel$ java test.java 
Exception in thread "main" java.lang.NoClassDefFoundError: test/java
Caused by: java.lang.ClassNotFoundException: test.java
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

2 个答案:

答案 0 :(得分:2)

您的测试类是什么包?

假设您尚未指定包,则要运行的命令为java test。通过运行“test.java”,它在名为“test”的包(目录)中查找名为“java”的类。

例如:

<强> test.java

class test {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

$ javac test.java
$ java test
Hello World

系统类路径位于/System/Library/Java/JavaConfig.plist。默认值为:

<key>DefaultClasspath</key>
    <string>$HOME/Library/Java:$NEXT_ROOT/Library/Java:$NEXT_ROOT/System/Library/Java:$NEXT_ROOT/Network/Library/Java:$NEXT_ROOT/System/Library/Frameworks/JavaVM.framework/Classes/classes.jar:$NEXT_ROOT/System/Library/Frameworks/JavaVM.framework/Classes/ui.jar</string>

答案 1 :(得分:-1)

试试这个,

java test

并且您的班级名称必须首字母大写,如Test