How to set the CLASSPATH to import jar package in a short format

Dennis Lee :

Can this way import multiple jars?

set CLASSPATH=C:\dependency\*;C:\location\*

Is this means all jars below the dependency is imported?

VioletTec :

Wildcards are allowed in the latest Java 6. See the document for details:

http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html


Let's take a look at this example

java -classpath "./libs/*" Test

The * here refers to all jar files in the LIBS directory. You can't write java -classpath "./libs/*. jar" test like this

If there are both jar files and class files in the LIBS directory, we all want to reference them, so we need to write

java -classpath "./libs/*;./libs/" Test

Note: in Windows system, the separator is; in UNIX system, the separator is:

Note that LIBS/* does not contain jar files in subdirectories under LIBS directory, such as LIBS/folder1/a.jar

If you want to include subdirectories, you need to be clear about them, such as

java -cp "./libs/*;./libs/folder1/*" Test

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=297107&siteId=1
Recommended