How to set environment variables for javac to be a

2019-08-30 00:21发布

问题:

I am not a java developer. I just want to run a java application (which can be downloaded from: http://code.google.com/p/k-shortest-paths/downloads/list , under this name: KShortestPaths_Java_v2.1.zip)

While trying to compile test\edu\asu\emit\qyan\test\YenTopKShortestPathsAlgTest.java I get "package ... does not exist" and "symbol ... does not exist" which I know are related to path setting. Can you please tell me how I should set environment variables and from which directory compile and run that java file? (My operating system is Windows XP and I have saved the application in C:\KSh)

Edit: I resolved the problem with compiling. Now, I have a CLASS file: YenTopKShortestPathsAlgTest. However, when I try to run it with java, I get this error: "could not find the main class... program will exist" which I guess is again related to the paths other jar files are located. Could you please kindly give me a hint?

回答1:

The zip file contains a .classpath and a .project file. These files are used by the eclipse java IDE.

Perhaps the most easy way would be to download eclipse and import the project there.

If you want to do it by hand, try

javac -sourcepath src;test test\edu\asu\emit\qyan\test\YenTopKShortestPathsAlgTest.java

from your directory C:\KSh.

EDIT:

Download junit.jar and add it to the classpath with

javac -classpath junit.jar -sourcepath....


回答2:

You need to point the classpath to the name of the .jar files, and/or the name of the directory containing your class files e.g.

CLASSPATH=c:\dir\myjar.jar;c:\classes

so you list the .jars required and the directories involved, separated by semicolons. You can either set the CLASSPATH environment variable, or use the above directly with javac thus:

javac -cp c:\dir\myjar.jar;c:\classes {source files}