[英]ClassNotFound Error when running Java .class file in Ubuntu terminal
I compile my file with javac myfile.java
But when I run myfile.class file with command : java myfile
I get an ClassNotFound error. 我使用
javac myfile.java
编译我的文件但是当我使用命令运行myfile.class文件时: java myfile
我得到一个ClassNotFound错误。 My Java version is openjdk-6 我的Java版本是openjdk-6
Run the command as this (in the same directory where you compiled): 像这样运行命令(在您编译的同一目录中):
java -cp . myfile
Assuming of course that the file contains a class called myfile
, which btw, doesn't follow standard Java naming practices (should begin with a capital letter). 当然假设文件包含一个名为
myfile
的类,btw不遵循标准的Java命名实践(应该以大写字母开头)。
Read up on here more about setting your runtime classpath. 请在此处阅读有关设置运行时类路径的更多信息。
Most likely your classpath is wrong. 您的类路径很可能是错误的。 Try java -cp .
试试java -cp。 myfile
MYFILE
Also, java tools tend to like javas normal conventions, so your class should be MyClass, and the file should then be MyClass.java 此外,java工具倾向于喜欢javas普通约定,所以你的类应该是MyClass,然后该文件应该是MyClass.java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.