How to run Java program in terminal with external library JAR
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
Compile and run java program with mutiple external jar files
If you want to add directory while contains all the required jars for running/ compiling your Java file you can use below command:
In Windows:
java -classpath ".;c:\lib*" MainClass
In UNIX/ Linux
java -classpath ".:/lib/*" MainClass
Note: In windows ;
(semicolon) is the separator, while in UNIX/ Linux :
(colon) is the separator for multiple jar for directory
.
(dot) represents current directory
Compile java program in command line with external .jar
when you are executing below line, you are getting the below error right ?
javac -cp paillier.jar CoupleGen.java
Error: Could not find or load main class CoupleGen
That means compiler is looking for the CouplenGen.java in paillier.jar. Actually CoupleGen is outside of the jar file.
run java from terminal that depend on external libraries
First off, you just need to pass the class name to java:
java -Djava.library.path="libs/natives/"
-cp libs/jars/lwjgl.jar:libs/jars/lwjgl_util.jar DisplayTest
(linebreaks for readability)
I would try the following:
1) Use the CLASSPATH enviroment variable, as in:
CLASSPATH=.:/path/to/lwjgl/lwjgl.jar:/path/to/lwjgl/lwjgl_util.jar
export CLASSPATH
Notice the dot (.) at the very beginning of the classpath;
2) Run your java application:
java -Djava.library.path="libs/natives" DisplayTest
If this works, add the commands above to a shell script. Good luck!
Java command line with external .jar
Concatenate each jar file argument to cp with:
; on Windows
: on Linux or Mac
e.g.
java -cp <path>\TOOLS.jar;.;<path>\jar2.jar;<path>\jar3.jar HelloWorld
on newer JVMs (6+, I think) you can also use the * to append all JARs in a directory e.g.
java -cp .;<path>\*; HelloWorld
To go a step further and create a single packaged executable see this question.
Related Topics
Check If One List Contains Element from the Other
Java.Exe Finished With Non-Zero Exit Value 1
Convert String With Dot or Comma to Float Number
Regex to Match Substring After Nth Occurence of Pipe Character
Tomcat Server Error - Port 8080 Already in Use
Java 8 Convert Utc Time to Edt/Est So That Date Remains the Same
Checking If a Document Exists in a Firestore Collection
Regex to Match a String Not Starting or Ending With a Pattern
How to Write a User Input Based Constructor
Java:Using Apache Poi How to Convert Ms Word File to Pdf
How to Beautifully Update a JPA Entity in Spring Data
How to Check Whether a Given String Is Valid Json in Java
How to Disable Error Highlighting in VS Code
How to Remove the Decimal Part If It Is Only 0
Can Not Deserialize Instance of Java.Util.Arraylist Out of Start_Object Token