0

How can I run a jar that needs several jars to work? Let me explain, I have for example a project with a jar "Main.jar" but to run this Main.jar I need jdom.jar(for xml file), jGit.jar...

Assume we need more than two jars. How can I run my Main.jar?

num3ric
  • 686
  • 5
  • 15
Mehdi
  • 2,160
  • 6
  • 36
  • 53
  • Put the jars in the classpath (the .jar file, not the directory it lies in) – SJuan76 Nov 05 '12 at 18:46
  • @Mehdi How are you running your Main.jar? The command line is referring to the terminal where you are executing commands. Eg. under Windows `cmd`. – dan Nov 05 '12 at 18:55

2 Answers2

1

Run the jar with main class and add all other jars to classpath.

java -cp yourJars yourClass

see this post for more info. See this java tutorial

Community
  • 1
  • 1
kosa
  • 65,990
  • 13
  • 130
  • 167
1

By including the needed jar files in the classpath. Something like:

 java -cp "Main.jar;jdom.jar;jdom.jar" MainClass

If you are under Windows and would like to execute the Main.jar with a double click, you will need to create a .bat file and use that one instead to run your program. The content of the .bat file will have the above command.

Under Unix/Linux you will create a shell file with the similar content.

Note that the -cp argument values will need to contain all the jars that your Main.jar is depended on.

dan
  • 13,132
  • 3
  • 38
  • 49