Java类路径和相对路径 [英] Java Classpath and relative paths
问题描述
如果在java类路径中有相对路径,那么这只是搜索当前工作目录。对清单文件中声明的类路径是否保持相同。在清单文件中它是相对于jar所在的目录吗?
If you have a relative path in the java class path, does this just search the current working directory. Does the same hold for class paths declared in a manifest file. In a manifest file is it relative to the dir the jar is in?
Ex。
Cmdline
Ex. Cmdline
java -cp somejar.jar
或
清单
Class-Path: somejar.jar
推荐答案
如果你说 -cp somejar.jar
你要将 somejar.jar
添加到类路径中。它只会尝试在您输入命令时从您当前所在的目录中找到 somejar.jar
。
If you say -cp somejar.jar
you are adding somejar.jar
to the classpath. It will only try to find the somejar.jar
from the directory you are currently in when you typed the command.
如果你在清单中说
Class-Path: somejar.jar
你是说将jar, somejar.jar
添加到清单所在目录的类路径中找到(也就是在jar中)。
you are saying add the jar, somejar.jar
into the classpath from the directory where the manifest is located(aka inside the jar).
作为旁注,当你使用-jar,-cp或-classpath指定类路径时,你会覆盖系统变量CLASSPATH。
As a side note, when you specify the classpath by using -jar, -cp, or -classpath, you override the system variable CLASSPATH.
更多细节可以在这里找到, http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
More details can be found here, http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
这篇关于Java类路径和相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!