Running a Java Program

后端 未结 5 1071
没有蜡笔的小新
没有蜡笔的小新 2021-01-21 06:38

I looked at some other SO questions, didn\'t find anything that solved my problem... I have a Main.java file (below) and a OthelloLib.jar file without associated source files.

相关标签:
5条回答
  • 2021-01-21 06:54

    Note: You can do all this within a good IDE like eclipse or netbeans by adding the library to your project. The rest gets handled automagically.

    0 讨论(0)
  • 2021-01-21 07:06

    Did you import all the libraries?

    like

    import a.b.c. OthelloPlayer;
    
    0 讨论(0)
  • 2021-01-21 07:07

    Did you specify the classpath when you call your program?

    Something like the following might work:

    java -cp .:OthelloLib.jar Main
    
    0 讨论(0)
  • 2021-01-21 07:11

    You run

    javac -classpath .:OthelloLib.jar Main.java
    

    to compile, then

    java -classpath .:OthelloLib.jar Main
    

    In each case the -classpath .:OthelloLib.jar option tells Java where to find SimplePlayer and other classes you need; it doesn't know to look in the JAR file on its own. And you do need to tell both the compiler and the virtual machine where to look for the classes.

    EDIT: Looks like you added something about TimeoutException since I wrote this... did you remember to compile TimeoutException.java? And is the TimeoutException.class file in the same directory as Main.class?

    0 讨论(0)
  • 2021-01-21 07:11

    Have you set a reference to OthelloLib.jar or invoking the javacompiler with the library as a parameter?

    java -classpath .:OthelloLib.jar -g Main
    
    0 讨论(0)
提交回复
热议问题