[java] How to run Java program in terminal with external library JAR

This should be simple but I have never done it before and didn't find any solution.

I am currently using Eclipse to code my program, which imports some external JAR library such as google data api library. I can use Eclipse to compile/build/run the program.

But now I want to run it in terminal, so where should I put those JAR files, and how to build and run the program?


This question is related to java jar

The answer is

You can do :

1) javac -cp /path/to/jar/file Myprogram.java

2) java -cp .:/path/to/jar/file Myprogram

So, lets suppose your current working directory in terminal is src/Report/

javac -cp src/external/myfile.jar Reporter.java

java -cp .:src/external/myfile.jar Reporter

Take a look here to setup Classpath

Similar questions with java tag:

Similar questions with jar tag: