Reputation: 93
I want to compile an eclipse java project from command line. To make it easier I've put all my java files and the jar file that I need in my program in one direcotry. The path to the said direcory is:
C:\Users\Besi\Desktop\Test\src
My main class is called Program.java
Now, I am having problems with importing the jar file and compiling my main class. I mean I cannot compile it without importing the jar file but at the same time I don't know how to this in the command line. I tried this:
javac -classpath ".:C:\Users\Besi\Desktop\Test\src\javatuples-1.2;" Program.java
but it doesn't work. Any advice?
Upvotes: 0
Views: 774
Reputation: 687
Assuming this is your end goal (and not simply trying to "add a jar file to an Eclipse java project from the command line" as your actual question title states):
I want to compile an eclipse java project from command line.
Turns out that you can compile your Eclipse project from the command line without having to place your .jar files and .java files in the same directory.
I just did it (and ensured I had two .jar files in my Eclipse project) using the following command as executed from the workspace directory (which I modified using the information from your question, assuming C:\Users\Besi\Desktop\Test
is the workspace of your project, and assuming you're running Windows):
eclipsec.exe -noSplash -data "C:\Users\Besi\Desktop\Test" -application org.eclipse.jdt.apt.core.aptBuild
Because I cannot yet comment, I am posting this as an answer, even though I adapted this answer based on the contents of a previous SO answer. Please edit accordingly if this causes any trouble, thanks.
Upvotes: 1