0

I have a java class I'm trying to run that references various other jar files. It looks something like this:

 package com.myapp.test;

 import java.io.File;
 import com.myapp.ref;
 import com.myapp.stuff;
 import com.strangersapp.stuff;
 import com.strangersapp.morestuff;

 public class myTest {
    public static void main... 
    ...
 }

The com.myapp.* classes are in another jar file called myapp.jar. The strangersapp classes are in a strangersapp.jar. There are several other referenced classes in various jars. My whole directory structure looks like this:

 myapp.jar
 strangersapp.jar
 someother.jar
 yetanother.jar
 etc.jar
 com\myapp\test\myTest.java

My problem is trying to compile and run this. I try the obvious but this command does NOT work. It doesnt pickup all the jar files:

 javac -cp . com\myapp\test\myTest.java
 java -cp . com.myapp.test.myTest

This command also does not work:

 javac -cp ".;*.jar" com\myapp\test\myTest.java

However, these commands do work:

 javac -cp ".;myapp.jar;strangersapp.jar;someother.jar;yetanother.jar;etc.jar" com\myapp\test\mTest.java
 java -cp ".;myapp.jar;strangersapp.jar;someother.jar;yetanother.jar;etc.jar" com.myapp.test.mTest

Would anyone know why my first java run statement is not working?? I dont want to type all the jar names out in the classpath reference...

John Lee
  • 1,179
  • 1
  • 12
  • 25

2 Answers2

0

If you use -cp you have to name all the jars you want to include. To avoid that just add them to your manifest and java will pick them up.

For javac i think you are supposed to use -classpath rather than -cp

benjamin.d
  • 2,599
  • 3
  • 15
  • 33
0

You should try this:

javac -cp ".;*.jar" com\myapp\test\myTest.java
java -cp ".;*.jar" com.myapp.test.myTest
Daniel Kaplan
  • 54,448
  • 39
  • 189
  • 282
  • I thought that was the right command too and tried it but get an NoClassDefFoundError. I've also tried the following: javac -classpath ".;*.jar" com\myapp\test\myTest.java That didnt work either... I'm using JDK 6 and also tried JDK 7 – John Lee Nov 13 '13 at 01:35