tags:

views:

228

answers:

1

Hi!

I run my application using mvn jetty:run

At compile time everything is fine, my row

  Tidy tidier = new Tidy();
    tidier.setInputEncoding("UTF-8");

compiles fine and the classpath shows the appropriate jar. However, at runtime I get the following exception and I cannot undestand why:

2009-11-11 17:48:53.384::WARN:  Error starting handlers
java.lang.NoSuchMethodError: org.w3c.tidy.Tidy.setInputEncoding(Ljava/lang/String;)V

I am now thinking maybe there are two different versions of this Tidy in my classpath (the one apparently is not named tidy, otherwise I could detect it in the classpath shown by maven). I am trying to find out what jar file it is and so far I have tried the following:

Class<?> tidyClass = Class.forName(Tidy.class.getName());
ClassLoader tidyLoader = tidyClass.getClassLoader();
String name = Tidy.class.getName() + ".class"; // results in tidyClass=class org.w3c.tidy.Tidy
System.out.println("resource="+tidyLoader.getResource(name)); // results in tidyLoader=org.codehaus.classworlds.RealmClassLoader@337d0f
System.out.println("path="+tidyLoader.getResource(name).getPath()); // results in resource=null

I read somewhere that the path should show the jar but apparently not with this classloader... how can I figure it out? Everything works like a charm in eclipse but when I run with maven I get this mess.. BTW eclipse says

tidyClass=class org.w3c.tidy.Tidy
tidyLoader=sun.misc.Launcher$AppClassLoader@1a7bf11
resource=null so no jar info either.
A: 

try something like this:

    Class clazz = null;
 try {
  clazz = Class.forName( typeName );
  if ( clazz != null && clazz.getProtectionDomain() != null
          && clazz.getProtectionDomain().getCodeSource() != null )
  {
   URL codeLocation = clazz.getProtectionDomain().getCodeSource()
           .getLocation();
   System.out.println( codeLocation.toString() );
  }
 }
 catch ( ClassNotFoundException e ) {
  System.out.println( e.getMessage() );
 }

where typeName="org.w3c.tidy.Tidy".

saleemshafi
Thank you. This worked like a charm as also did understanding that the classname should be relative to its classpath:tidyClass.getResource(Tidy.class.getSimpleName() + ".class") = ar:file:/C:/Program Files/maven-2.0.7/bin/../lib/maven-core-2.0.7-uber.jar!/org/w3c/tidy/Tidy.classMore similar instructions at: http://forums.sun.com/thread.jspa?threadID=5341830However, maven-core-2.0.7-uber.jar!/org/w3c/tidy/Tidy.class poses a new problem! That Tidy is not the one that works with my App and I do not know how to override it!
Martin
See <a href="http://stackoverflow.com/questions/1716726/how-to-override-maven-core-2-0-7-uber-jar">follow-up question</a>.
Martin