ClassNotFoundException error when running css-validator.jar

旧时模样 提交于 2019-12-11 08:15:53

问题


I am trying to implement css-validator from w3 and it has failed with every attempt, raising an error message.

Here is the error I am getting:

"Directory Redacted"\framework-web>java -jar "Directory Redacted"\Downloads\
css-validator.jar http://www.w3.org
Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/tools/resourc
es/ProtocolException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
    at java.lang.Class.getMethod0(Class.java:2774)
    at java.lang.Class.getMethod(Class.java:1663)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)

Caused by: java.lang.ClassNotFoundException: org.w3c.tools.resources.ProtocolExc
eption
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 6 more

What exactly does this error message indicate and how do I fix it?


回答1:


I was very grateful when cluemein included the actual filenames but without the original versions and which ones were renamed, I still couldn't get css-validator to run. So I downloaded the most recent css-validator.jar and the most recent build.xml file from http://dev.w3.org/cvsweb/2002/css-validator/build.xml?rev=1.24;content-type=text%2Fplain.

I put the build.xml file and the jar in a directory and ran

ant prepare

Ant downloaded the expected jar versions for me and renamed them into the lib file. Then when I ran

java -jar css-validator.jar http://awesomesite.com

it worked fine.




回答2:


It would appear the application is using the class 'ProtocolException':

http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/tools/resources/ProtocolException.html

It's likely that it is missing from your classpath. I would see if you can add the containing jar to your ant classpath.

Also if you take a look at Sinan's answer here: How can I validate CSS on internal web pages?

Was there an ant build file which came with the application? If so, it might be as simple as running ant against that build.xml to get your dependencies, then run java -jar through command line.




回答3:


Ok, it turns out I was missing 8 prerequisite .jar files that are needed for this to work. I put them in a folder titled lib in the same folder as css-validator.jar and it works perfectly afterward. The files are:

  1. commons-collections-3.2.1.jar
  2. commons-lang-2.6.jar
  3. htmlparser-1.3.1.jar
  4. jigsaw.jar
  5. tagsoup-1.2.jar
  6. velocity-1.7.jar
  7. xercesImpl.jar
  8. xml-apis.jar

Was a lot more than I expected that I was missing. The documentation for css-validator.jar did not have the complete list, had to dance around the internet and even rename some jar files to make it work (removed version number for some of these.) If anyone else wants to use css-validator.jar, you will need these files



来源:https://stackoverflow.com/questions/24274483/classnotfoundexception-error-when-running-css-validator-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!