1

我正在尝试从 w3 实现 css-validator,但每次尝试都失败,引发错误消息。

这是我得到的错误:

"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

此错误消息究竟表明了什么,我该如何解决?

4

3 回答 3

3

看起来应用程序正在使用类“ProtocolException”:

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

您的类路径中可能缺少它。我会看看你是否可以将包含的jar添加到你的 ant 类路径中。

另外,如果您在这里查看思南的回答: 如何在内部网页上验证 CSS?

应用程序附带了一个 ant 构建文件吗?如果是这样,它可能就像针对该 build.xml 运行 ant 以获取依赖项一样简单,然后通过命令行运行 java -jar。

于 2014-06-17T23:57:54.767 回答
2

好的,事实证明我丢失了 8 个必备的 .jar 文件,这些文件需要这些文件才能正常工作。我将它们放在一个名为 lib 的文件夹中,该文件夹与 css-validator.jar 位于同一文件夹中,之后它可以完美运行。这些文件是:

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

比我预期的要多得多,我失踪了。css-validator.jar 的文档没有完整的列表,不得不在互联网上跳舞,甚至重命名一些 jar 文件以使其工作(删除了其中一些的版本号。)如果其他人想使用 css-validator .jar,您将需要这些文件

于 2014-06-30T20:03:52.183 回答
2

当 cuemein 包含实际文件名但没有原始版本以及哪些被重命名时,我非常感激,我仍然无法让 css-validator 运行。所以我从http://dev.w3.org/cvsweb/2002/css-validator/build.xml?rev=1.24;content-type=下载了最新的 css-validator.jar 和最新的 build.xml 文件文本%2Fplain

我将 build.xml 文件和 jar 放在一个目录中并运行

ant prepare

Ant 为我下载了预期的 jar 版本并将它们重命名为 lib 文件。然后当我跑

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

它工作得很好。

于 2014-09-29T21:13:53.583 回答