java 错误路径警告,它来自哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1344202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 16:11:18  来源:igfitidea点击:

Bad path warning, where is it coming from?

javacompiler-warnings

提问by Yishai

When I compile my project with compiler warnings (JDK 1.5) I get a bunch of bad path element warnings:

当我使用编译器警告(JDK 1.5)编译我的项目时,我收到了一堆错误的路径元素警告:

Warning:: [path] bad path element "C:\Users\User\MyJava\common\lib\junit.jar": no such file or directory Warning:: [path] bad path element "C:\Users\User\MyJava\common\lib\jdom.jar": no such file or directory Warning:: [path] bad path element "C:\Users\User\MyJava\common\lib\xerces.jar": no such file or directory Warning:: [path] bad path element "C:\Users\User\MyJava\common\lib\xml-apis.jar": no such file or directory

警告:: [路径] 错误路径元素“C:\Users\User\MyJava\common\lib\junit.jar”:没有这样的文件或目录警告:: [路径] 错误路径元素“C:\Users\User\ MyJava\common\lib\jdom.jar”:没有这样的文件或目录警告::[路径]错误的路径元素“C:\Users\User\MyJava\common\lib\xerces.jar”:没有这样的文件或目录:: [path] bad path element "C:\Users\User\MyJava\common\lib\xml-apis.jar": 没有这样的文件或目录

and many more.

还有很多。

This is using IDEA 8.1.3. I can't find anywhere in IDEA's configuration (I grepped the whole project) where anything points to these files. They are all indeed not there anymore under that name, but what references them?

这是使用 IDEA 8.1.3。我在 IDEA 的配置中找不到任何指向这些文件的地方(我对整个项目进行了搜索)。他们确实都不再以那个名字存在了,但是是什么引用了他们?

回答by Brent Writes Code

I think @Yishai has the right of it (I'll give him an up-vote for getting the ball rolling). I run into this all the time. In what I think was a horrible decision for the Java language, they decided it would be alright to allow classpath settings to go into the MANIFEST files inside jar files. So essentially, Jars can have files inside them that point to other classes and jars located elsewhere and when those other things they point to don't exist, you see warnings like the ones you're getting. These warnings are coming out of Jar files that are on your compilation classpath. So what you need to do if you really care is track down the problem jar files, extract the contents of the jar files, remove the "Class-Path" settings in their manifest files and recreate them. Something like this (move the jar to a temp directory somewhere first):

我认为@Yishai 有权这样做(我会给他投赞成票)。我一直遇到这个。我认为对于 Java 语言来说这是一个可怕的决定,他们认为允许类路径设置进入 jar 文件中的 MANIFEST 文件是可以的。所以基本上,Jars 可以在其中包含指向位于其他地方的其他类和 jar 的文件,当它们指向的其他东西不存在时,您会看到与您收到的警告类似的警告。这些警告来自编译类路径上的 Jar 文件。因此,如果您真的关心,您需要做的是追踪有问题的 jar 文件,提取 jar 文件的内容,删除其清单文件中的“类路径”设置并重新创建它们。

#Extract the jar file
jar xvf myfile.jar
rm myfile.jar
emacs ./META-INF/MANIFEST.MF

*Find the entry "Class-path:" and remove it completely and save the changes

#Rebuild the jar file
jar cvf myfile.jar ./*

That should do the trick!

这应该够了吧!

I don't think you just want to suppress these messages because if you want full control over what's going onto your classpath, you should search out these manifest files and make sure they don't mess with the classpath in a way you don't know about.

我不认为你只是想抑制这些消息,因为如果你想完全控制你的类路径上发生的事情,你应该搜索这些清单文件并确保它们不会以你不知道的方式与类路径混淆知道关于。

Likely you'll have to look through a ton of jar files, so I usually end up using a shell loop to help me look through them. You can copy all your Jars in question to a temporary directory and run a loop like this (bash syntax):

可能您必须查看大量 jar 文件,因此我通常最终使用 shell 循环来帮助我查看它们。您可以将所有有问题的 Jars 复制到一个临时目录并运行这样的循环(bash 语法):

for i in *.jar; do echo $i; jar xf $i; grep -i 'class-path' ./META-INF/MANIFEST.MF; done

That will print the name of every Jar file in the current directory, extract its contents, and grep its manifest file for classpath entries. If the name of the jar file in the output has a "Class-Path" printout after it, that means that Jar has classpath settings in its manifest. This way you can hopefully figure out what Jars you need to take action on.

这将打印当前目录中每个 Jar 文件的名称,提取其内容,并为类路径条目 grep 其清单文件。如果输出中 jar 文件的名称后面有“Class-Path”打印输出,则意味着 Jar 在其清单中具有类路径设置。通过这种方式,您有望弄清楚需要对哪些 Jars 采取行动。

回答by Yishai

According to this, the issue is that in third party jars there is a reference to these in the manifest. The message can be disabled by adding -Xlint:-path to the compilation parameters.

根据这个,问题是,在第三方坛子里有在manifest这些参考。可以通过将 -Xlint:-path 添加到编译参数来禁用该消息。

回答by Avi

Have you checked the places that your CLASSPATH environment variable, and compilation option, is being set?

您是否检查过正在设置 CLASSPATH 环境变量和编译选项的位置?

回答by Lawrence Dol

The path elements in question are most likely in a JAR's manifest file. To locate the offending JAR you can run this shell script which will extract only the manifest files and show any classpath it has:

有问题的路径元素很可能在 JAR 的清单文件中。要找到有问题的 JAR,您可以运行此 shell 脚本,该脚本将仅提取清单文件并显示它具有的任何类路径:

for i in *.jar; do echo $i; /path/to/your/jdk/bin/jar xf $i META-INF/MANIFEST.MF; grep -i 'class-path' META-INF/MANIFEST.MF; done