user1122000 user1122000 - 17 days ago 6
Java Question

compile and run java code written on Eclipse on cmd prompt

I am trying to run a java project that includes two libraries

jpbc-api-1.2.1.jar
and
jpbc-plaf-1.2.1.jar
. The code has been written on Eclipse and I am now trying to run it on the cmd prompt on a Windows machine. I went to the .classpath file and made sure to modify the paths as follows:

classpathentry kind="lib" path="lib/jpbc-api-1.2.1.jar" sourcepath="lib/jpbc-api-1.2.1.jar"

classpathentry kind="lib" path="lib/jpbc-plaf-1.2.1.jar" sourcepath="jpbc-plaf-1.2.1.jar"


Whenever I try to compile my java code I get the following error:


error: cannot find symbol


To compile I used the command:


javac filename.java


That is obviously because the compiler cannot locate the files I am trying to show the path to. Is there a specific way to compile and run the code?

Answer

You don't need the compiler to run the program if it's already compiled by Eclipse - you only need the Java runtime. The .classpath file is Eclipse-specific, so it won't be used by either the Java compiler (javac) or the Java runtime (java).

Assuming that your main class is called com.my.MainClass and your classes directory is called "myclasses", you would run your class using this command line:

java -classpath lib/jpbc-api-1.2.1.jar;lib/jpbc-plaf-1.2.1.jar;myclasses com.my.MainClass

I think you should have a look at the documentation of the Java command line tools: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html

Good luck!