I have a Java project, which runs fine in Eclipse. Right now, I need to run it using command line, like java classpath
. How do I setup the classpath based on the stored ones using in Eclipse?
Say you have changed directories to be in your project directory, and directly underneath that are a bin directory that has your compiled classes and a lib directory that has your jar files. Also let's say the class with the main method you want to invoke is com.initech.example.EntryPoint. On windows you can run:
java -cp bin;lib\*.jar com.initech.example.EntryPoint
The slashes go the other way for Unix, obviously, and you use colon instead of semicolon as a separator in the cp switch.
Using -jar to run your project only works if your classes are packaged in a jar file (duh) and the jar file has a manifest that gives the entry point.
Simply navigate to the directory that the class file exists in and use
java -classpath . myClass
Edit: You can replace the .
with any classpath. For example, to find your classpath you can use echo %CLASSPATH%
Edit: Looks like there's quite a bit of information that might help you here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With