简体   繁体   中英

Why -classpath option not working on java 1.8

on my system has

C:\Users\Ravi>java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

how when I run

C:\Users\Ravi>java -classpath="C:\Users\Ravi\jar\" -Dcom.android.monkeyrunner.bindir=..\framework -jar monkeyrunner-26.0.0-dev.jar
Unrecognized option: -classpath=C:\Users\Ravi\jar\
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Please let me know what I am doing wrong.

In documentation there is:

--class-path classpath, -classpath classpath, or -cp classpath A semicolon (;) separated list of directories, JAR archives, and ZIP archives to search for class files.

Specifying classpath overrides any setting of the CLASSPATH environment variable. If the class path option isn't used and classpath isn't set, then the user class path consists of the current directory (.).

As a special convenience, a class path element that contains a base name of an asterisk ( ) is considered equivalent to specifying a list of all the files in the directory with the extension.jar or.JAR. A Java program can't tell the difference between the two invocations. For example, if the directory mydir contains a.jar and b.JAR, then the class path element mydir/ is expanded to A.jar:b.JAR, except that the order of JAR files is unspecified. All.jar files in the specified directory, even hidden ones, are included in the list. A class path entry consisting of an asterisk (*) expands to a list of all the jar files in the current directory. The CLASSPATH environment variable, where defined, is similarly expanded. Any class path wildcard expansion that occurs before the Java VM is started. Java programs never see wildcards that aren't expanded except by querying the environment, such as by calling System.getenv("CLASSPATH").

So you should rather have it like this (list all jars):

java -classpath "C:\Users\Ravi\jar\a.jar;C:\Users\Ravi\jar\b.jar" -Dcom.android.monkeyrunner.bindir=..\framework -jar monkeyrunner-26.0.0-dev.jar

To read more about classpath you can also look here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM