1

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
cluemein
  • 884
  • 13
  • 27
  • Does http://stackoverflow.com/questions/1137884/is-there-an-open-source-css-validator-that-can-be-run-locally help any? – demongolem Jun 19 '14 at 15:24
  • Not really. Many of the links in there are dead, and the instructions that are given are ones I have already tried, or simply don't give enough information (where is lib for instance?). – cluemein Jun 19 '14 at 16:29
  • Why did you put the word "correctly" into the title? It adds absolutely zero value; at best it insults your audience by suggesting that they need this reminder ("Please no wrong answers"). Title space is scarce as it is, and you should *really* think twice about what you write, especially in titles. (Same goes for "to work". As opposed to what - "to not interact at all with"?) – Kerrek SB Jun 30 '14 at 19:58
  • Ah, sorry, didn't mean to come off like that. will change. – cluemein Jun 30 '14 at 20:05
  • No worries, just trying to help you write more effective questions... – Kerrek SB Jun 30 '14 at 20:08
  • 1
    thanks. Trying real hard to fix a lot of mine because I found I can't ask any questions right now. – cluemein Jun 30 '14 at 20:14
  • Reopening question for votes on answers and possible other solutions/refinements of solutions. – cluemein Jan 04 '16 at 19:09
  • Possible duplicate of [How can I validate CSS on internal web pages?](https://stackoverflow.com/questions/1137884/how-can-i-validate-css-on-internal-web-pages) – Sinan Ünür Jun 12 '17 at 16:07
  • @SinanÜnür These aren't exactly internal web pages. Secondly, this was about a specific error initially. – cluemein Jul 19 '17 at 18:38

3 Answers3

3

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.

Community
  • 1
  • 1
Josh Rosso
  • 43
  • 5
  • I did run ant against build.xml. I also read that post. How do I add this package to my ant class path when my ANT_HOME already has the Ant path in it? Also I don't know where lib is. – cluemein Jun 18 '14 at 14:23
  • And what does having the ProtocolException in class path help to begin with? That seems like a useless and even possibly harmful action. You don't put Java Classes in class path. You put Java runtimes, file/program associations in those (assuming you are talking about environmental variables). Basically, what would be more useful, was where lib is and what it means by having it in the same directory as lib? I can't find lib. – cluemein Jun 18 '14 at 15:09
  • 1
    cluemein - Yes, apologies i meant to point the classpath to the library which it appears your code is dependent on. It does sound very much like a dependency issue in regards to the build process not grabbing your necessary dependencies. Sorry I couldn't be of more help. – Josh Rosso Jun 18 '14 at 19:37
  • Actually you were right, but, it wasn't the only thing missing. There were atleast 5 jar files it depended on, each containing many classes. – cluemein Jun 20 '14 at 20:40
  • 1
    Ah makes sense. Glad you figured it out! – Josh Rosso Jun 25 '14 at 19:30
2

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

cluemein
  • 884
  • 13
  • 27
2

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.

k-den
  • 853
  • 13
  • 28
  • 1
    I think part of the issue was that I was using a custom build file. The other was that I didn't know ant could download files, if I understood you right. – cluemein Sep 30 '14 at 02:14
  • You did! I actually started looking for a maven pom.xml file and was surprised that they were using ant to download the files as well. – k-den Sep 30 '14 at 16:12