我看了一些其他的SO问题,没有找到任何解决我的问题的东西......我有一个Main.java文件(下面)和一个没有关联源文件的OthelloLib.jar文件。运行Java程序
运行javac Main.java
失败
Main.java:8: cannot find symbol symbol : class SimplePlayer location: class Main OthelloPlayer p1 = new SimplePlayer();和一些更多的错误。 SimplePlayer和BetterPlayer在jar中定义。我如何告诉java这个jar?此命令:
javac -classpath .:OthelloLib.jar -g Main.java
不会导致错误,但我仍然不知道如何运行该程序。如果我运行
java -classpath .:OthelloLib.jar Main
,java的抱怨:
Exception in thread "main" java.lang.NoClassDefFoundError: TimeoutException
但TimeoutException.java是在同一个目录中Main.java。
我不知道在哪里查找这样的基本Java东西,所以我在这里!
public class Main {
public Main() { }
public static void main(String[] args) {
OthelloPlayer p1 = new SimplePlayer();
OthelloPlayer p2 = new BetterPlayer();
OthelloObserver o = new OthelloSimObserver();
// Create an untimed game
OthelloGame g = new OthelloGame(p1, p2, o);
System.out.println("Starting game");
g.run();
}
}
'公共的Main(){}'是不必要的。并不是每个类都需要一个构造函数,并且因为它什么都不做,它只是混淆了你的代码。 – Imagist 2009-09-18 04:53:49
几年前某个类的遗留代码。我很高兴java不需要那样。 :) – 2009-09-18 06:57:26