0

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?

Bes Sa
  • 83
  • 1
  • 3
  • 13
  • What is the structure inside the Test\src folder? Is javatuples-1.2 a jar? – Mike R Dec 28 '13 at 21:49
  • yes, javatuples-1.2 is a jar. Inside Test\src folder I have all my java files (including Program.java) that I want to compile and javatuples-1.2 jar – Bes Sa Dec 28 '13 at 21:53
  • 1
    Try `".:C:\Users\Besi\Desktop\Test\src\*"` see http://stackoverflow.com/questions/219585/setting-multiple-jars-in-java-classpath – Mike R Dec 28 '13 at 21:56
  • or just add the .jar extension to `javatuples-1.2.jar` – Mike R Dec 28 '13 at 22:03
  • Thank you, but I tried both and I still get errors related to the lack of javatuples jar – Bes Sa Dec 29 '13 at 15:21

1 Answers1

1

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.

Community
  • 1
  • 1
bunting
  • 687
  • 1
  • 6
  • 11
  • Thank you but I will have to compile this project from an svn repository and very likely on a computer that does not have eclipse installed so I cannot use this method – Bes Sa Dec 28 '13 at 22:27
  • Understood, I will update if I find a more generic solution. Please include that information in the question next time :). – bunting Dec 28 '13 at 22:40
  • @BesSa can you update the question to ask for a generic solution that does not use Eclipse so future answers can be useful to you? – bunting Dec 29 '13 at 01:45