Java - Build and run eclipse project from command line

JavaEclipse

Java Problem Overview


I have a java project written using eclipse ide and I want to run it through ssh on a different machine, but I have to do this using the command line and I don't know exactly how.

I am a beginner at both shell commands and java.

Could you please give me a useful link with answers regarding this question, or perhaps a set instructions of how to do this?

Java Solutions


Solution 1 - Java

Maven or Ant are the best option but for an Eclipse-only solution
you can choose File -> Export and select Java -> Runnable JAR File
then transfer the JAR file to your other machine and run this from the command line:

java -jar YOUR.JAR

Solution 2 - Java

You can run Java applications from the command line. The simplified syntax looks like this:

java -cp <classpath> <main class> <args>

where:

<classpath> - list of directories and/or JAR-files where needed classes reside separated by ";" for Windows or ":" for linux (default classpath is "." - the current directory);

<main class> - fully qualified name of the class containig main() method (for example, org.myself.HelloWorld)

<args> - various arguments for application if any.

So, if you find the directory where Eclipse stored compiled classes (usually it's bin) you may use the command, like

java -cp . my.package.MyClass

Or, if you use some libraries and classes in other directories, it could be:

java -cp some-cool-lib.jar:another-lib.jar:/some/directory/with/classes my.package.MyClass

Solution 3 - Java

To build and run a Java project, Its good to use an ant or maven tool. you can find many tutorials on google for the same.

a good tutorial on ant is here http://www.intranetjournal.com/java-ant/

Solution 4 - Java

This is what I did and it worked for me. Hope it could help. enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSimonView Question on Stackoverflow
Solution 1 - JavaRuss HaywardView Answer on Stackoverflow
Solution 2 - JavaxappymahView Answer on Stackoverflow
Solution 3 - JavaGuruKulkiView Answer on Stackoverflow
Solution 4 - JavafoxwendyView Answer on Stackoverflow