Here is the thing: I am trying to run the example program in the joda-time project. The start of the Examples.java file looks like this:
事情是这样的:我试图在joda-time项目中运行示例程序。 Examples.java文件的开头如下所示:
package org.joda.example.time;
import java.util.Locale;
import org.joda.time.DateTime;
import org.joda.time.Instant;
/**
* Example code demonstrating how to use Joda-Time.
*
* @author Stephen Colebourne
*/
public class Examples {
public static void main(String[] args) throws Exception {
try {
new Examples().run();
} catch (Throwable ex) {
ex.printStackTrace();
}
}
And all the classes for compiling this Example.java is in a joda-time-2.3.jar. I can successfully compile this program by using
编译这个Example.java的所有类都在joda-time-2.3.jar中。我可以通过使用成功编译该程序
javac -cp somewhere/joda-time-2.3.jar Example.java
And it generate an Example.class, but I jut cannot execute that. So far I have tried:
它生成一个Example.class,但我不能执行它。到目前为止,我尝试过:
java Examples
java -cp somewhere/joda-time-2.3.jar Examples
java -cp somewhere/joda-time-2.3.jar org.joda.example.time.Examples
But they all generate this kind of errors:
但它们都会产生这种错误:
Error: Could not find or load main class org.joda.example.time.Example
错误:无法找到或加载主类org.joda.example.time.Example
Error: Could not find or load main class Examples
错误:无法找到或加载主类示例
And I've tried both in the org/joda/example/time folder and the parent folder of org
我在org / joda / example / time文件夹和org的父文件夹中都尝试过
Anyone can give an instruction on how to execute that? Really appreciate it!
任何人都可以指示如何执行该操作?真的很感激!
2 个解决方案
#1
1
Modify your classpath parameter, so it should include directory where Example.class was generated.
修改classpath参数,因此它应该包含生成Example.class的目录。
In case of out/org/joda/example/time/Example.class you need to use
如果是out / org / joda / example / time / Example.class则需要使用
java -cp somewhere/jodata-time-2.3.jar:out org.joda.example.time.Example
#2
3
Error: Could not find or load main class org.joda.example.time.Example
错误:无法找到或加载主类org.joda.example.time.Example
public class Examples {
Name of your class is Examples
not Example
您的类的名称是示例而不是示例
EDIT
Sorry for late reply...
抱歉回复晚了...
To execute specific Java program you need to bring control to root directory so if your class is in abc/newdir/Examples.java
you need to use cd
command (in windows) to lead control to root directory and than compile or you can defeneitly go for the suggestion of kogut.
要执行特定的Java程序,你需要将控制权带到根目录,所以如果你的类在abc / newdir / Examples.java中,你需要使用cd命令(在windows中)将控制权引导到根目录而不是编译或者你可以肯定地去对于kogut的建议。
C:/abc/newdir>java -cp somewhere/joda-time-2.3.jar Examples
#1
1
Modify your classpath parameter, so it should include directory where Example.class was generated.
修改classpath参数,因此它应该包含生成Example.class的目录。
In case of out/org/joda/example/time/Example.class you need to use
如果是out / org / joda / example / time / Example.class则需要使用
java -cp somewhere/jodata-time-2.3.jar:out org.joda.example.time.Example
#2
3
Error: Could not find or load main class org.joda.example.time.Example
错误:无法找到或加载主类org.joda.example.time.Example
public class Examples {
Name of your class is Examples
not Example
您的类的名称是示例而不是示例
EDIT
Sorry for late reply...
抱歉回复晚了...
To execute specific Java program you need to bring control to root directory so if your class is in abc/newdir/Examples.java
you need to use cd
command (in windows) to lead control to root directory and than compile or you can defeneitly go for the suggestion of kogut.
要执行特定的Java程序,你需要将控制权带到根目录,所以如果你的类在abc / newdir / Examples.java中,你需要使用cd命令(在windows中)将控制权引导到根目录而不是编译或者你可以肯定地去对于kogut的建议。
C:/abc/newdir>java -cp somewhere/joda-time-2.3.jar Examples