0

Suppose I have two jar files (with classes inside) and a java file:

name1.jar
name2.jar
code.java

As said at How to use classes from .jar files?, if I wanted to import name1.jar, I could add it to my CLASSPATH, and run

javac -cp '.:name1.jar' code.java

every time I wanted to import name1.jar. However, how would I compile the java code and import both jar files, not just name1.jar?

3 Answers 3

1

try this

javac -cp name1.jar:name2.jar code.java

note that if you are in Windows path separator should be ;

Sign up to request clarification or add additional context in comments.

Comments

0

The java command can also define the classpath using the -cp flag, which is just a shortcut for the -classpath flag.

(1)javac -cp "/yourPath/name1.jar;/yourPath/name2.jar;" code.java

(2)javac -classpath "/yourPath/name1.jar;/yourPath/name2.jar;" code.java

Comments

0
java -cp name1.jar:name2.jar:name3.jar code.java arg1 arg2 arg3

this code runs code.java class with jars (name1,name2,name3) -cp used to ignore any runnable jar or other main() and focus on run code.java with arguments arg1 arg2 arg3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.