How to set environment variables for javac to be able to find imported packages?

吃可爱长大的小学妹 提交于 2019-12-12 04:35:39

问题


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}


来源:https://stackoverflow.com/questions/2167820/how-to-set-environment-variables-for-javac-to-be-able-to-find-imported-packages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!