How to add multiple jar files in classpath in linux
You use the -classpath
argument. You can use either a relative or absolute path. What that means is you can use a path relative to your current directory, OR you can use an absolute path that starts at the root /
.
Example:
bash$ java -classpath path/to/jar/file MyMainClass
In this example the main
function is located in MyMainClass
and would be included somewhere in the jar file.
For compiling you need to use javac
Example:
bash$ javac -classpath path/to/jar/file MyMainClass.java
You can also specify the classpath via the environment variable, follow this example:
bash$ export CLASSPATH="path/to/jar/file:path/tojar/file2"
bash$ javac MyMainClass.java
For any normally complex java project you should look for the ant script named build.xml
Adding multiple jars to classpath on commandline
Remove the spaces from the classpath and add the current path
javac -cp jar/A.jar:jar/B.jar:jar/C.jar:jar/D.jar:. MyFile.java
Since Java 6 you can use classpath wilcards
javac -cp jar/*:. MyFile.java
set java classpath to multiple folders that have jar files and run from command line
Here is the solution that finally worked as expected. When the '*' character is used in the classpath for my specific scenario, it skipped everything after the first path. Using the double quotes(") for each path separately and then using ";" as the delimiter is the solution.
Having any space before or after the semi-colon ";" will also not work
javac -verbose -classpath "C:\Program Files\lib\java\core\*";"C:\Program Files\lib\java\core\locale\*";"C:\Program Files\lib\java\modules\*";"C:\Program Files\lib\java\modules\ext\*" testClass.java
How to add multiple .jar files in the javac/java class path - for Debian Linux
Separate the class path entries by :
colons, not spaces.
Adding multiple jar files into classpath
The * syntax for classpaths is rather limited. Try:
java -classpath "~/twitter4j-2.2.6/lib/*:." GetHashtag
spark submit add multiple jars in classpath
I was trying to connect to mysql from the python code that was executed using spark-submit
.
I was using HDP sandbox that was using Ambari. Tried lot of options such as --jars
, --driver-class-path
, etc, but none worked.
Solution
Copy the jar in /usr/local/miniconda/lib/python2.7/site-packages/pyspark/jars/
As of now I'm not sure if it's a solution or a quick hack, but since I'm working on POC so it kind of works for me.
Related Topics
Decibel Values at Specific Points in Wav File
Httpservletrequest Get JSON Post Data
How Does Linux Recognize a File as a Certain File Type, and How to Programmatically Change It
Error Playing Audio File from Java via Pulseaudio on Ubuntu
Linux Start-Up Script for Java Application
Create Directory with Write Permissions for the Group
What Would Cause a Java Process to Greatly Exceed the Xmx or Xss Limit
Converting a String to Hexadecimal in Java
Concurrentmodificationexception for Arraylist
Why Is 08 Not a Valid Integer Literal in Java
Fill an Array With Random Numbers
Animation on Transparent-Background Jframe Linux
Set Margins in a Linearlayout Programmatically
Image Encryption/Decryption Using Aes256 Symmetric Block Ciphers
How to Convert a Color Integer to a Hex String in Android
How to Get the First Day of the Current Week and Month
Why Does Java Rmi Keep Connecting to 127.0.1.1. When Ip Is 192.168.X.X