views:

474

answers:

4

I want to check internal web pages, so I cannot use the W3C validation service directly. I managed to run the XHTML validator locally, however, I have some problems with the css-validator. I do not really want to setup Tomcat or Jigsaw in order to be able to run Java servlet, and the commandline option give me an error message

Exception in thread "main" java.lang.NoClassDefFoundError: org.w3c.tools.resources.ProtocolException at org.w3c.css.css.CssValidator.main(CssValidator.java:164)

Does anybody know of an alternative that I can run locally on a Linux box?

+1  A: 

What about the Firefox addon?

Itay Moav
Check your spelling, it's addons, not addson. Otherwise I agree, this is a nice tool
Rich Seller
The firefox addon only calls the w3c service which cannot access my web pages. This would not help, but thanks.
txwikinger
+6  A: 

You can invoke the W3C validator from the command line:

Command-Line use

Any computer with Java installed can also run the validator from the terminal/console as a commandline tool. Download the css-validator.jar jar archive (or build it with ant jar) and run it as :

java -jar css-validator.jar http://www.w3.org/

Note : the css-validator.jar file must be located at the exact same level as the lib/ folder to work properly.

Update: To get it to work, I checked out the full distribution from CVS and ran ant using the included build.xml. It downloaded all dependencies except for servlet.jar. To deal with that, I downloaded the binary distribution of Tomcat 6 and extracted it. Then, I edited the build.xml for css-validator to reflect the location of servlet.lib:

<property name="servlet.lib" 
 value="E:/Downloads/apache-tomcat-6.0.20/lib/servlet-api.jar"/>

Then ran ant again. This produced the css-validator.jar file in the top level of the directory checked out from CVS with the lib subdirectory containing the other jars it depends on. Then, I was able to run the validator successfully:

C:\Temp\validator\2002\css-validator> java -jar css-validator.jar http://www.unur.com/

Sinan Ünür
Well.. I tried that, but I get above error message. I am not sure that I understand the meaning of the note. It does not work either if put into the /lib folder. Which lib folder is meant here?
txwikinger
I think I get it. I downloaded the source code from CVS from http://dev.w3.org/cvsweb/2002/css-validator/ ... I have not built it yet, but it seems like running the validator from the command line still needs to be in the context of Jigsaw. I think that is the `/lib` directory the docs are referring to.
Sinan Ünür
Thanks. This solved my problem!
txwikinger
+3  A: 

The W3C CSS validator can be downloaded to run locally

mas
I tried that but get the error message that it does not find a main class
txwikinger
A: 

Here's a script I wrote to do what Sinan suggests (also fixes the ant script to find Xerces):

#!/bin/sh
# W3C CSS Validator --------------
# installs W3C CSS Validator
# 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/
##wget "http://www.w3.org/QA/Tools/css-validator/css-validator.jar"
#sudo aptitude install -y ant
CVSROOT=:pserver:anonymous:[email protected]:/sources/public cvs checkout 2002/css-validator 
mkdir 2002/css-validator/lib
wget "http://www.apache.org/dist/tomcat/tomcat-6/v6.0.28/bin/apache-tomcat-6.0.28.tar.gz"
tar xvf apache-tomcat-6.0.28.tar.gz
mv apache-tomcat-6.0.28/lib/servlet-api.jar 2002/css-validator/lib/servlet.jar
rm -rf apache-tomcat-6.0.28 apache-tomcat-6.0.28.tar.gz
cd 2002/css-validator
mv build.xml build.xml.ORIGINAL
sed -e 's/Xerces-J-bin.2.9.1./Xerces-J-bin.2.10.0./g' -e 's/xerces-2_9_1/xerces-2_10_0/g' build.xml.ORIGINAL > build.xml
ant jar
# usage example: java -jar css-validator.jar "http://csszengarden.com/"

That should work, at least until the next software dependency update breaks the ant build script (feel free to parameterize versions).

Hope this helps!

Noyo