运行 helloworld 时出错 +类路径问题
我正在编译 helloworldapp,没有错误。
我正在跑步 java 你好世界应用程序 在 Windows
CLASSPATH 上: .;C:\Program Files\Java\jre7\lib;
JAVA_HOME: C:\Program Files\Java\jre7
路径包括 C:\Program Files\Java\jdk1.7.0\bin\
结果:
C:\Users\k\Desktop\abcl-bin-0.26.2>java helloworldapp
Exception in thread "main" java.lang.NoClassDefFoundError: helloworldapp (wrong
name: HelloWorldApp)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
............etc
好吧,由于某种原因它找不到类,所以我尝试手动完成。
C:\Users\k\Desktop\abcl-bin-0.26.2>java -cp "C:\Program Files\Java\jre7\lib" helloworldapp
Error: Could not find or load main class helloworldapp
C:\Users\k\Desktop\abcl-bin-0.26.2>java -cp C:\Program Files\Java\jre7\lib; helloworldapp
Error: Could not find or load main class Files\Java\jre7\lib;
我做错了什么? 我浏览了几个论坛,但它们并不是特别有帮助。
更新,我已经过了 helloworld 阶段。 现在真正的问题
import org.armedbear.lisp.*;
public class Main
{
public static void main(String[] argv)
{
try
{
Main thisObject = new Main();
Interpreter interpreter = Interpreter.createInstance();
interpreter.eval("(load \"lispfunctions.lisp\")");
org.armedbear.lisp.Package defaultPackage =
Packages.findPackage("CL-USER");
Symbol voidsym =
defaultPackage.findAccessibleSymbol("VOID-FUNCTION");
Function voidFunction = (Function) voidsym.getSymbolFunction();
voidFunction.execute(new JavaObject(thisObject));
}
catch (Throwable t)
{
System.out.println("exception!");
t.printStackTrace();
}
}
public int addTwoNumbers(int a, int b)
{
return a + b;
}
}
我尝试了
C:\Users\k\Desktop\abcl-bin-0.26.2>java -cp abcl.jar Main
Error: Could not find or load main class Main
C:\Users\k\Desktop\abcl-bin-0.26.2>java -cp abcl.jar main
Error: Could not find or load main class main
abcl.jar 位于同一个文件夹中
一些更多的尝试和错误
C:\Users\k\Desktop\abcl-bin-0.26.2>java -cp .:abcl.jar Main
Error: Could not find or load main class Main
C:\Users\k\Desktop\abcl-bin-0.26.2>java Main -cp .:abcl.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/armedbear/lisp/Li
spObject
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.armedbear.lisp.LispObject
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
I am compiling helloworldapp with no errors.
I am running
java helloworldapp
on windows
CLASSPATH:
.;C:\Program Files\Java\jre7\lib;
JAVA_HOME:
C:\Program Files\Java\jre7
path includes
C:\Program Files\Java\jdk1.7.0\bin\
Result:
C:\Users\k\Desktop\abcl-bin-0.26.2>java helloworldapp
Exception in thread "main" java.lang.NoClassDefFoundError: helloworldapp (wrong
name: HelloWorldApp)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
............etc
So ok, for some reson it couldn't find the classes, so I am trying to do it manually.
C:\Users\k\Desktop\abcl-bin-0.26.2>java -cp "C:\Program Files\Java\jre7\lib" helloworldapp
Error: Could not find or load main class helloworldapp
C:\Users\k\Desktop\abcl-bin-0.26.2>java -cp C:\Program Files\Java\jre7\lib; helloworldapp
Error: Could not find or load main class Files\Java\jre7\lib;
What am I doing wrong?
I have looked at several forums, but they weren't particularly helpful.
Update, I got past the helloworld stage.
Now the real problem
import org.armedbear.lisp.*;
public class Main
{
public static void main(String[] argv)
{
try
{
Main thisObject = new Main();
Interpreter interpreter = Interpreter.createInstance();
interpreter.eval("(load \"lispfunctions.lisp\")");
org.armedbear.lisp.Package defaultPackage =
Packages.findPackage("CL-USER");
Symbol voidsym =
defaultPackage.findAccessibleSymbol("VOID-FUNCTION");
Function voidFunction = (Function) voidsym.getSymbolFunction();
voidFunction.execute(new JavaObject(thisObject));
}
catch (Throwable t)
{
System.out.println("exception!");
t.printStackTrace();
}
}
public int addTwoNumbers(int a, int b)
{
return a + b;
}
}
I tried both
C:\Users\k\Desktop\abcl-bin-0.26.2>java -cp abcl.jar Main
Error: Could not find or load main class Main
C:\Users\k\Desktop\abcl-bin-0.26.2>java -cp abcl.jar main
Error: Could not find or load main class main
The abcl.jar is located in the same folder
Some more trials and errors
C:\Users\k\Desktop\abcl-bin-0.26.2>java -cp .:abcl.jar Main
Error: Could not find or load main class Main
C:\Users\k\Desktop\abcl-bin-0.26.2>java Main -cp .:abcl.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/armedbear/lisp/Li
spObject
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.armedbear.lisp.LispObject
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当你用java编写类时,文件名必须与类名匹配。
必须保存为 HelloWorldApp.java
它必须与大小写匹配,即 helloworldapp.java 不起作用。
当您需要运行该类时,必须使用正确的大小写来引用它。
但不是
如果您引用 JAR,那么您需要将其添加到您的类路径中。默认情况下,类路径由当前工作目录中的文件组成。
在 Windows 上,类路径是一个以分号 (;) 分隔的列表,在 Linux 和 Mac OSX 上,它是一个冒号 (:) 分隔的列表。
要将 JAR 包含在类路径中,您必须运行以下命令...
其中 myjar.jar 是您要引用的 JAR 文件,MyMainClass 是包含您的 <公共静态无效主要方法。
When you write a class in java, the name of the file must match the name of the class.
must be saved as HelloWorldApp.java
It must match the case i.e. helloworldapp.java would not work.
When you need to run the class, you must refer to it using the correct case.
but not
If you are referencing a JAR then you need to add it to your classpath. By default the classpath consists of the files in the current working directory.
On windows the classpath is a semi-colon (;) separated list, on Linux and Mac OSX it is a colon (:) separated list.
To include the JAR in the classpath you must run the following...
where myjar.jar is the JAR file you want to reference and MyMainClass is the class that contains your public static void main method.