[英]Java: tips to add classpath
I have both a library.jar and program.jar in Java folder. 我在Java文件夹中同时有一个library.jar和program.jar。
What is the correct command line to run? 要运行的正确命令行是什么? One method I tried is:
我尝试的一种方法是:
C:>java -cp c:\java\library.jar;.\java\program.jar program [param]
Try 尝试
java -cp c:\java\library.jar;.\java\program.jar package.the.MainClass [param]
From http://download.oracle.com/javase/1.3/docs/tooldocs/win32/classpath.html 从http://download.oracle.com/javase/1.3/docs/tooldocs/win32/classpath.html
Folders and archive files
文件夹和档案文件
When classes are stored in a directory (folder), like
当类存储在目录(文件夹)中时,例如
c:\\java\\MyClasses\\utility\\myapp, then
the class path entry points to the directory that contains the first element of the package name.
类路径条目指向包含包名称的第一个元素的目录。 (in this case,C:\\java\\MyClasses, since the package name is utility.myapp.)
(在这种情况下,C:\\ java \\ MyClasses,因为程序包名称为Utility.myapp。)
But when classes are stored in an archive file (a .zip or .jar file) the class path entry is the path to and including the .zip or .jar file.
但是,当类存储在存档文件(.zip或.jar文件)中时,类路径条目是.zip或.jar文件的路径,包括该路径。 For example, to use a class library that is in a .jar file, the command would look something like this:
例如,要使用.jar文件中的类库,该命令将如下所示:
C:> java -classpath C:\\java\\MyClasses\\myclasses.jar utility.myapp.Cool
Multiple specifications
多种规格
To find class files in the directory C:\\java\\MyClasses as well as classes in C:\\java\\OtherClasses, you would set the class path to:
要在目录C:\\ java \\ MyClasses以及C:\\ java \\ OtherClasses中的类中找到类文件,请将类路径设置为:
C:> java -classpath C:\\java\\MyClasses;C:\\java\\OtherClasses ...
Note that the two paths are separated by a semicolon.
请注意,两条路径用分号分隔。
如果你想为你的program.jar是一个可执行的JAR,你必须运行这种方式(读此 ):
java -jar program.jar
Classpath entries can also contain the wildcard(*) character. 类路径条目也可以包含通配符(*)。 For example, the class path entry
C:\\java\\*
specifies all JAR files in the C:\\java
directory and will be expanded into C:\\java\\library.jar;C:\\java\\program.jar
. 例如,类路径条目
C:\\java\\*
指定C:\\java
目录中的所有JAR文件,并将其扩展为C:\\java\\library.jar;C:\\java\\program.jar
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.