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
How to compile java project with external jar file in Linux terminal
You never use slashes, which are path delimiters, in a call to java (but to javac). If src is part of your package declaration - in this case the whole package declaration, which I bet it is not, you would, instead of:
java -cp .:lib/jsoup-1.6.1.jar src/DayTradingStockBlog
use a dot:
java -cp .:lib/jsoup-1.6.1.jar src.DayTradingStockBlog
But I guess it is just the place where you created the class, so the path belongs to the classpath:
java -cp .:lib/jsoup-1.6.1.jar:./src DayTradingStockBlog
You aren't free to omit the path from the Class name, and append it to the classpath, or vice versa - it has to fit to your package declaration.
If you declare a package foo
, (which has much more sense than src), your class name is no longer DayTradingStockBlog
but foo.DayTradingStockBlog
.
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
how to include external jar files while creating a jar file in linux?
There are two ways.
- Create a MANIFEST.MF that refers to the other jar in its classpath
- Whenever you run the program, make sure you include both jars in your classpath.
That said, I think you should go back and read a tutorial because you've made a few mistakes in your question.
- "hello.java" is not a jar file as you've said. This is a java source file. It will be compiled into a class file. You can take this class file and put it in a jar file.
- You can't name your manifest file "myManifest.txt" AFAIK. It has to be named something specific and be located in a specific place. Read a tutorial to see the details on that.
include external jar when running java -jar
Is there a reason why you are avoiding invoking the main class like
java -cp /usr/local/jar/foobar.jar:/some/other/path.jar com.your.main.classname
?
This type of invocation allows you to mix absolute paths with relative paths. Put this into a shell script or batch file to avoid having to actually type or remember the full classpath to simplify things.
Related Topics
Listview Onitemclicklistener Not Responding
Division in Java Always Results in Zero (0)
How to Check If an App Running on Android
Get Battery Level and State in Android
How to Know Whether Enough Memory Is Free to Deploy a New Application on a Linux MAChine
How to Set Java_Home Path on Ubuntu
Android N Change Language Programmatically
Android - Span_Exclusive_Exclusive Spans Cannot Have a Zero Length
Error:(23, 17) Failed to Resolve: Junit:Junit:4.12
Java.Lang.Numberformatexception: Invalid Double: " "
Limit Decimal Places in Android Edittext
Wait Until Firestore Data Is Retrieved to Launch an Activity
Android Studio 3.1.3 Gradle Sync Error. Could Not Download Gradle-Core.Jar
How to Programmatically Set Drawableleft on Android Button