坏路径警告,它来自哪里? [英] Bad path warning, where is it coming from?

查看:180
本文介绍了坏路径警告,它来自哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

警告:: [路径]坏路径元素 C:\ Users \User \ MyJava\common \lib \ junit.jar:没有这样的文件或目录
警告:: [路径]坏路径元素C:\ Users \ User\MyJava\common\lib\jdom.jar:没有这样的文件或目录
警告:: [路径]坏路径元素C:\ Users \ User \ MyJava \ common \ lib \ xerces.jar:没有这样的文件或目录
警告:: [路径]坏路径元素C:\Users \User \ MyJava \ common \ lib \ xml- apis.jar:没有这样的文件或目录

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

还有更多。

这是使用IDEA 8.1。 3。我无法在IDEA的配置中找到任何地方(我对整个项目进行了深入研究),其中任何内容都指向这些文件。他们在这个名字下确实不存在,但是什么引用了它们?

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?

推荐答案

我认为@Yishai有权利(我会给他一个投票让球滚动)。我一直遇到这种情况。在我认为对Java语言的可怕决定中,他们认为允许类路径设置进入jar文件中的MANIFEST文件是可以的。基本上,Jars可以在其中包含指向位于其他地方的其他类和ja​​r的文件,当它们指向的其他东西不存在时,您会看到类似于您获得的警告。这些警告来自编译类路径中的Jar文件。因此,如果您真正关心的话,您需要做的是跟踪问题jar文件,提取jar文件的内容,删除其清单文件中的Class-Path设置并重新创建它们。像这样的东西(首先将jar移到某个临时目录):

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):

#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.

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

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):

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

这将打印当前目录中每个Jar文件的名称,提取其内容,以及grep它的类路径条目的清单文件。如果输出中的jar文件的名称后面有Class-Path打印输出,则表示Jar在其清单中有类路径设置。这样你就可以找出你需要采取行动的罐子。

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.

这篇关于坏路径警告,它来自哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆