Search code examples
javaclasspathjavac

How do you pass multiple paths to Java -cp command?


So I am trying to compile a file that imports code from 2+ different .jar files.

The following is the command I am using to compile my file:

javac -cp /home/ugrads/majors/quinnliu/workspace/WalnutiQ/build/libs/WalnutiQ.jar:. HowMARK_II_FitsInToBrainAnatomy.java

Now I am getting an error because I am calling code in another .jar file in another folder but I don't know how to add it correctly to my current -cp command above.

Sample of errors I am getting:

HowMARK_II_FitsInToBrainAnatomy.java:3: error: package com.google.gson does not exist
import com.google.gson.Gson;

Solution

  • Use:

    javac -cp jar1.jar;jar2.jar source1.java source2.java ...
    

    On Windows you have to use semicolon to separate the JAR files, but on Unix you can use a colon.