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...
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
You should try this:
javac -cp ".;*.jar" com\myapp\test\myTest.java
java -cp ".;*.jar" com.myapp.test.myTest
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.