Bad path warning, where is it coming from?

后端 未结 4 944
野性不改
野性不改 2021-02-02 10:02

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

Warning:: [path] bad path element \"C:\\Users\\User\\MyJava\\commo

相关标签:
4条回答
  • 2021-02-02 10:23

    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.

    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
    

    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.

    0 讨论(0)
  • 2021-02-02 10:25

    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.

    0 讨论(0)
  • 2021-02-02 10:28

    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:

    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
    
    0 讨论(0)
  • 2021-02-02 10:31

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

    0 讨论(0)
提交回复
热议问题