我想检查内部网页,因此我无法直接使用W3C validation服务。我设法在本地运行XHTML验证器,但是,我遇到了css-validator的一些问题。我真的不想设置Tomcat或Jigsaw以便能够运行Java servlet,命令行选项会给我一个错误消息
Exception in thread "main" java.lang.NoClassDefFoundError:
org.w3c.tools.resources.ProtocolException at
org.w3c.css.css.CssValidator.main(CssValidator.java:164)
如何在Linux机器上验证本地CSS?
答案 0 :(得分:11)
That jar是可运行的,但它需要一些额外的库。
检查MANIFEST.MF
文件:
$ unzip -p css-validator.jar META-INF/MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.0
Created-By: 1.6.0_26-b03 (Sun Microsystems Inc.)
Main-Class: org.w3c.css.css.CssValidator
Class-Path: . lib/commons-collections-3.2.1.jar lib/commons-lang-2.6.j
ar lib/jigsaw.jar lib/tagsoup-1.2.jar lib/velocity-1.7.jar lib/xerces
Impl.jar lib/xml-apis.jar lib/htmlparser-1.3.1.jar
您需要Class-Path
中提到的所有广告罐。您可以使用以下脚本从maven repository下载它们:
#!/bin/bash
set -e
mkdir -p lib
curl -LO http://www.w3.org/QA/Tools/css-validator/css-validator.jar
echo "\
http://repo1.maven.org/maven2/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
http://repo1.maven.org/maven2/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
http://repo1.maven.org/maven2/org/w3c/jigsaw/jigsaw/2.2.6/jigsaw-2.2.6.jar jigsaw.jar
http://repo1.maven.org/maven2/org/ccil/cowan/tagsoup/tagsoup/1.2/tagsoup-1.2.jar
http://repo1.maven.org/maven2/org/apache/velocity/velocity/1.7/velocity-1.7.jar
http://repo1.maven.org/maven2/xerces/xercesImpl/2.11.0/xercesImpl-2.11.0.jar xercesImpl.jar
http://repo1.maven.org/maven2/nu/validator/htmlparser/htmlparser/1.2.1/htmlparser-1.2.1.jar\
" | while read url shortname; do
if [ -z "$shortname" ]; then
shortname="${url##*/}"
fi
curl -L -o "lib/${shortname}" "${url}"
done
完成后,它可以工作:
$ java -jar css-validator.jar --output=soap12 file:badcss.html
{vextwarning=false, output=soap12, lang=en, warning=2, medium=all, profile=css3}
<?xml version='1.0' encoding="utf-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Body>
<m:cssvalidationresponse
env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
xmlns:m="http://www.w3.org/2005/07/css-validator">
<m:uri>file:badcss.html</m:uri>
<m:checkedby>http://jigsaw.w3.org/css-validator/</m:checkedby>
<m:csslevel>css3</m:csslevel>
<m:date>2013-03-12T06:40:09Z</m:date>
<m:validity>false</m:validity>
<m:result>
<m:errors xml:lang="en">
<m:errorcount>1</m:errorcount>
<m:errorlist>
<m:uri>file:badcss.html</m:uri>
<m:error>
<m:line>8</m:line>
<m:errortype>parse-error</m:errortype>
<m:context> h1 </m:context>
<m:errorsubtype>
exp
</m:errorsubtype>
<m:skippedstring>
100%
</m:skippedstring>
<m:message>
Property fnt-size doesn't exist :
</m:message>
</m:error>
</m:errorlist>
</m:errors>
<m:warnings xml:lang="en">
<m:warningcount>1</m:warningcount>
<m:warninglist>
<m:uri>file:badcss.html</m:uri>
<m:warning>
<m:line>5</m:line>
<m:level>0</m:level>
<m:message>You should add a 'type' attribute with a value of 'text/css' to the 'style' element</m:message>
</m:warning>
</m:warninglist>
</m:warnings>
</m:result>
</m:cssvalidationresponse>
</env:Body>
</env:Envelope>
答案 1 :(得分:8)
您可以从命令行调用W3C validator:
命令行使用
任何安装了Java的计算机都可以 也运行验证器 终端/控制台作为命令行 工具。下载css-validator.jar jar存档(或使用ant jar构建) 并按以下方式运行:
java -jar css-validator.jar http://www.w3.org/
注意:
css-validator.jar
文件必须 位于与...完全相同的水平 lib /文件夹才能正常工作。
更新为了让它发挥作用,我检查了CVS的完整发布,并使用附带的ant
运行build.xml
。它下载了除servlet.jar
之外的所有依赖项。为了解决这个问题,我下载了Tomcat 6的二进制分发版并将其解压缩。然后,我修改了build.xml
的{{1}}以反映css-validator
的位置:
servlet.lib
然后再次运行<property name="servlet.lib"
value="E:/Downloads/apache-tomcat-6.0.20/lib/servlet-api.jar"/>
。这会在从CVS检出的目录的顶层生成ant
文件,其中css-validator.jar
子目录包含它依赖的其他lib
。然后,我能够成功运行验证器:
jar
答案 2 :(得分:5)
对于懒惰人来说,这是我写的一个剧本,用来做思南建议的事情:
#!/bin/sh
# W3C CSS Validator Install Script --------------
# installs W3C CSS Validator
# requires: ant, wget, javac
# see: http://jigsaw.w3.org/css-validator/DOWNLOAD.html
# see: http://esw.w3.org/CssValidator
# see: http://thecodetrain.co.uk/2009/02/running-the-w3c-css-validator-locally-from-the-command-line/
# see: http://stackoverflow.com/a/3303298/357774
##wget "http://www.w3.org/QA/Tools/css-validator/css-validator.jar"
#sudo aptitude install -y ant # uncomment if you don't have ant
CVSROOT=:pserver:anonymous:anonymous@dev.w3.org:/sources/public cvs checkout 2002/css-validator
mkdir 2002/css-validator/lib
TOMCAT6_VERSION='6.0.45'
wget "http://www.apache.org/dist/tomcat/tomcat-6/v$TOMCAT6_VERSION/bin/apache-tomcat-$TOMCAT6_VERSION.tar.gz"
tar xvf apache-tomcat-$TOMCAT6_VERSION.tar.gz
mv apache-tomcat-$TOMCAT6_VERSION/lib/servlet-api.jar 2002/css-validator/lib/servlet.jar
rm -rf apache-tomcat-$TOMCAT6_VERSION apache-tomcat-$TOMCAT6_VERSION.tar.gz
cd 2002/css-validator
ant jar
# usage example: java -jar css-validator.jar "http://csszengarden.com/"
这应该可行,至少在下一个软件依赖项更新破坏了ant构建脚本之前(随意参数化版本)。
希望这有帮助!