0

I downloaded a package in java, which I'll call package1, and I created a second package, which I'll call package2. package2 has a reference to package1.

Now I need to export package1 to a JAR. I exported it (and in the process created a manifest file that specified the main file of the package).

When running package1 from the commandline (java -jar package1.jar), how do I "connect" it to package2? That is, when I run java -jar package1.jar I get errors about not finding specific classes that appear in package2.

Cheshie
  • 2,777
  • 6
  • 32
  • 51
  • You need to add package2 also into the classpath – Bacteria May 31 '15 at 19:13
  • @Arin - thanks, I'm not sure how...? – Cheshie May 31 '15 at 19:14
  • Follow these links 1>http://stackoverflow.com/questions/219585/setting-multiple-jars-in-java-classpath 2>http://stackoverflow.com/questions/2096283/including-jars-in-classpath-on-commandline-javac-or-apt – Bacteria May 31 '15 at 19:16
  • Also view this link "5 ways to add multiple JAR in to Classpath in Java" :http://javarevisited.blogspot.in/2012/10/5-ways-to-add-multiple-jar-to-classpath-java.html – Bacteria May 31 '15 at 19:18
  • Please add the full error you're getting, including after trying the suggestions here. – John Ament May 31 '15 at 19:23

2 Answers2

1

You should add package2.jar to -cp argument to your java command line:

java -cp package2.jar -jar package1.jar
Forketyfork
  • 7,416
  • 1
  • 26
  • 33
0

This should work at least on windows:

java -cp "package1.jar;package2.jar" com.example.app.Main

where com.example.app is the path down the packages to your main class and Main is your main class.

chris
  • 1,685
  • 3
  • 18
  • 28