Statement:
Java-CP.; myclass. Jar packname. mainclassname
-The CP parameter is followed by a Class path, which specifies to the interpreter where to find your. Class file,
The jar file in classpath can use wildcards. If multiple jar files are used, they must be listed one by one. In a sense, the JAR file is the path.
You must specify the storage path for each jar file. The same path has multiple wildcards.
Java-CP.; C:/classes/myclass. jar; D:/classes/*. Jar packname. mainclassname
Packname. mainclassname is the fully qualified class name that contains the main method. If there are multiple classes with the main method in classpath, you can use this command to conveniently select the program entry.
1. jar-CP lib/referenced. Jar-Jar myworks. jar will run the following error:
When we use -jar.pdf, java.exe ignores-CP,-classpath, and the Environment Variable classpath parameters.
Solution 1:
Do not use the-jar option to directly call the class file containing the main method, so that the parameters specified by-CP,-classpath and classpath in the environment variables can be used.
Java-classpath./lib/JUnit. jar:. Test/test1
Solution 2:
Continue to use the-jar option, but specify to reference the JAR file in the mainfest. MF file.
Class-path: myplace/myjar. Jar myplace/other. Jar jardir/
Another note: some people may not be able to solve this problem. Due to different Java versions, I have encountered this problem in Sun's JDK and IBM 1.5 JDK, but there is no similar problem with JDK of IBM 1.4.
2. How to load packages in batches
(1) The-CP parameter can be used when the Java command introduces the jar, but the-CP cannot use wildcards (multiple jar files must be written one by one, not *. jar). Generally, the jar files are in the same directory and there are more than one. A parameter-djava. Ext. dirs ~ was just found a few days ago ~
For example, Java-djava. ext. dirs = lib myclass [the same WebLogic has the following parameter:-dweblogic. ext. dirs = $ bea_home/patch_weblogic920/profiles/default/sysext_manifest_classpath]
(2) Set classpath for loading through Unix shell (shell is really convenient)
Classpath = 'Find ../lib-name *. Jar | xargs | sed "S //:/g "'
Classpath = ".: $ classpath
(3) The CP parameter is followed by a Class path, which specifies to the interpreter where to find your. Class file. You can use the Java-CP command to call a class with the main function under another directory. The format is the path of the Java-CP class file. The following example uses the relative path.
String CommandLine = "Java-CP" + ".. \ kwicbypipeserver \ bin kwic ";
PROCESS p = runtime.getruntime(cmd.exe C (CommandLine );
In this way, you can call it.
(4) You can add the classpath variable to the Environment Parameter in windows;