开发者

Run Jar related .Java from cmd

开发者 https://www.devze.com 2023-04-05 11:15 出处:网络
I am trying to do "javac Classname.java" from cmd prompt, and this Classname.java requires Jfreechart libraries/jars开发者_Python百科, and runs fine if compiled from Eclipse (because project

I am trying to do "javac Classname.java" from cmd prompt, and this Classname.java requires Jfreechart libraries/jars开发者_Python百科, and runs fine if compiled from Eclipse (because project package has jars imported).

But I want to run the file from cmd prompt and its not able to show me the output. It comes with errors like: ("package doesn't exist"), how to fix it? I need the class file and also run JNI commands to create header file.


You need to set the classpath.

You can do this in 2 ways. Either use the -classpath or -cp option:

javac -cp jar1.jar;path/to/jar2.jar Classname.java

Or, if you need it to persist, use the CLASSPATH environmental variable:

set CLASSPATH=path1;path2
javac Classname.java


If you have already managed to run your code in Eclipse, then Eclipse can help you.

In the "Debug" view, you should have something like this remaining after you have run your code:

Run Jar related .Java from cmd

If you right-click the bottom "terminated" text and select "Properties", you will get something like this:

Run Jar related .Java from cmd

You can copy the command line content and use that to run your app from the command line, or use it to set the classpath as the other answers have advised.


You just need to add the directory paths and/or .jar libraries to your "-classpath" command-line argument.

Depending on how many libraries you've got, you might well wind up with a .sh script (Linux) or .cmd file (windows) that looks something like this:

http://ubuntuforums.org/showthread.php?t=230258

java -cp jts.jar:jcommon-1.0.0.jar:jfreechart-1.0.0.jar:jhall.jar:other.jar:rss.jar -Xmx256M jclient.LoginFrame .

If you're on Windows, you'd use ";" as a separator (instead of *nix ":").

'Hope that helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号