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
Running Java command including all JARs in current folder
You've answered your own question, sort of.
.
means that it will look for .class
files in the current directory.
JARs act just like a directory. So to have the abc.jar "directory" you would specify abc.jar
in your classpath.
If you need both the .class
files present in the current directory, and the .class
files packaged into JARs found in the current directory, you would have the following classpath: -cp ".:*.jar
All the answers here are telling you to use the wildcard without extension (*
or ./*
) but this is a bad practice, you don't want Java to go look into irrelevant files, so specify the extension: *.jar
.
javac classpath option with multiple jar files in current directory causing error
The quoted sources for the two links provided in the comments as well as in the "This question may already have an answer here:", do not completely explain the observed behavior.
javac -cp ./*.jar MyFile.java
Won't work, because the wildcard * usage in this context differs from normal usage. This can be understood from the documentation. * always represents full file(s) and not partial file names.
javac -cp ./* MyFile.java
Should have worked. Apparently using double quotes and/or a semi-colon in windows. works:
javac -cp "./*" MyFile.java
javac -cp ./*; MyFile.java
javac -cp "./*;" MyFile.java
javac -cp *; MyFile.java
javac -cp "*" MyFile.java
javac -cp "*;" MyFile.java
Nowhere in the documention is this important fact mentioned afaik.
So I guess ON WINDOWS 7 64 bit, with java 1.6.0_75 EITHER USE DOUBLE QUOTES OR ALWAYS A SEMI-COLON WHEN USING WILDCARD *
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
Add all jar files to java classpath except of some ones
In Linux or OS X using this will do the job:
ls -1 $PWD/foo/*.jar | grep -v 'unwanted1.jar\|unwanted2.jar' | tr '\n' ':'
So you can use it together with java
command:
java -cp `ls -1 $PWD/foo/*.jar | grep -v 'unwanted.jar\|unwanted2.jar' | tr '\n' ':'` ...
Set folder for classpath
If you are using Java 6 or higher you can use wildcards of this form:
java -classpath ".;c:\mylibs\*;c:\extlibs\*" MyApp
If you would like to add all subdirectories: lib\a\, lib\b\, lib\c\, there is no mechanism for this in except:
java -classpath ".;c:\lib\a\*;c:\lib\b\*;c:\lib\c\*" MyApp
There is nothing like lib\*\*
or lib\**
wildcard for the kind of job you want to be done.
Related Topics
How to Create Recyclerview With Multiple View Types
Download a File With Android, and Showing the Progress in a Progressdialog
How to Pass an Object from One Activity to Another on Android
Setting Singleton Property Value in Firebase Listener
How to Launch an Activity from Another Application in Android
View'S Getwidth() and Getheight() Returns 0
How to Call a Method After a Delay in Android
Calling a Java Method from C++ in Android
How to Send Http Request in Java
Converting HTML to Pdf Using Itext
How to "Scan" a Website (Or Page) For Info, and Bring It into My Program
Example Images For Code and Mark-Up Q&As
Find Div Element by Multiple Class Names
How to Return Datasnapshot Value as a Result of a Method
Sending Email in Android Using Javamail API Without Using the Default/Built-In App