简体   繁体   English

可以为 -classpath (java) 提供相对路径吗

[英]Can Relative path be provided for -classpath (java)

Can I do this:我可以这样做吗:

javac -classpath ././My_Jars/*;././My_Other_Jars/* -d bin Test.java

Above command always throws ClassNotfound!上面的命令总是抛出 ClassNotfound! (My_Jars not found and My_Other_jars not found) (未找到 My_Jars 和未找到 My_Other_jars)

Java: JDK 6 OS: Windows 7 Java:JDK 6 操作系统:Windows 7

You should use .. (double dots) rather than .您应该使用.. (双点)而不是. (single dot - which refers to current directory) for using relative paths. (单点 - 指的是当前目录)用于使用相对路径。

The asterisks in a class path is not a wild card but instead tell loads the classes from jar files.类路径中的星号不是通配符,而是告诉从 jar 文件加载类。 If your classes are not in jars then you would just use <path>/.如果您的课程不在 jars 中,那么您只需使用<path>/.

But given your names, I do not think that is the issue.但鉴于你的名字,我认为这不是问题。 You may want to try:您可能想尝试:

javac -classpath ./../My_Jars/*;./../My_Other_Jars/* -d bin Test.java 

if your Jars are one level up from the current working directory.如果您的 Jars 是当前工作目录的上一级。

I suspect that the problem is not the relative path, but the use of wildcards (the asterixs).我怀疑问题不是相对路径,而是通配符(星号)的使用。 These are actually expanded by the command line environment (the shell) - and in this case would not probably give what you are expecting.这些实际上是由命令行环境(shell)扩展的 - 在这种情况下,可能不会给出您所期望的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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