user1122000 user1122000 - 1 year ago 93
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

. 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:


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 Source

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 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

I think you should have a look at the documentation of the Java command line tools:

Good luck!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download