简体   繁体   English

运行css-validator.jar时发生ClassNotFoundException错误

[英]ClassNotFoundException error when running css-validator.jar

I am trying to implement css-validator from w3 and it has failed with every attempt, raising an error message. 我正在尝试从w3实现css-validator,并且每次尝试均失败,并引发错误消息。

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? 此错误消息确切说明了什么,我该如何解决?

It would appear the application is using the class 'ProtocolException': 看来应用程序正在使用类'ProtocolException':

http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/tools/resources/ProtocolException.html 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. 我会看看是否可以将包含的jar添加到您的ant类路径中。

Also if you take a look at Sinan's answer here: How can I validate CSS on internal web pages? 另外,如果您在此处查看Sinan的答案: 如何验证内部网页上的CSS?

Was there an ant build file which came with the application? 该应用程序附带一个ant构建文件吗? 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. 如果是这样,那么可能很简单,只要对那个build.xml运行ant来获取依赖关系,然后通过命令行运行java -jar即可。

Ok, it turns out I was missing 8 prerequisite .jar files that are needed for this to work. 好的,事实证明,我缺少此功能需要的8个必备.jar文件。 I put them in a folder titled lib in the same folder as css-validator.jar and it works perfectly afterward. 我将它们放在与css-validator.jar相同的文件夹中的lib文件夹中,此后它可以完美地工作。 The files are: 这些文件是:

  1. commons-collections-3.2.1.jar commons-collections-3.2.1.jar
  2. commons-lang-2.6.jar commons-lang-2.6.jar
  3. htmlparser-1.3.1.jar htmlparser-1.3.1.jar
  4. jigsaw.jar 拼图
  5. tagsoup-1.2.jar tagsoup-1.2.jar
  6. velocity-1.7.jar 速度-1.7.jar
  7. xercesImpl.jar xercesImpl.jar
  8. xml-apis.jar 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 css-validator.jar的文档没有完整的列表,不得不在互联网上跳舞,甚至重命名一些jar文件才能使其正常工作(其中一些版本已删除。)如果其他人想要使用css-validator .jar,您将需要这些文件

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. 当cluemein包含实际的文件名但没有原始版本以及将其重命名时,我非常感激,但我仍然无法运行css-validator。 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 . 因此,我从http://dev.w3.org/cvsweb/2002/css-validator/build.xml?rev=1.24;content-type=下载了最新的css-validator.jar和最新的build.xml文件。 文字%2Fplain

I put the build.xml file and the jar in a directory and ran 我将build.xml文件和jar放在目录中并运行

ant prepare

Ant downloaded the expected jar versions for me and renamed them into the lib file. Ant为我下载了预期的jar版本,并将其重命名为lib文件。 Then when I ran 那我跑的时候

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

it worked fine. 工作正常。

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

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