How to tell javac which libraries to include

So I am trying to run a java file from Terminal. But the file is using the apache.commons.io lib, so a simple javac MyFile.java does not work here.

How do you include the libraries in Terminal?

1

1 Answer

You need first to install libcommons-io-java:

sudo apt-get install libcommons-io-java

Then use the installed jar file with javac this way:

javac my_file.java -cp /usr/share/java/commons-io.jar

From the javac man pages:

 -cp path or -classpath path Specify where to find user class files, and (optionally) annota‐ tion processors and source files. This class path overrides the user class path in the CLASSPATH environment variable. If neither CLASSPATH, -cp nor -classpath is specified, the user class path consists of the current directory. See Setting the Class Path for more details.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like