0 Replies Latest reply on Aug 25, 2005 7:42 AM by B.S.Navin

    NoClassDefFoundError & LinkageError on deployment

    B.S.Navin Newbie

      I deployed a .sar with a service MBean that loads an XML and parses it with the "Commons Digester" component. The corresponding commons-digester.jar & dependent jars are also included in the .sar

      My sar has defined a separate loader repository as multiple instances of the service can be deployed on the same JBoss server. When I deploy this into the "default" configuration of JBoss 3.2.x with "java2ParentDelegation=false", it works just fine.

      But when I use "java2ParentDelegation=true", I get the following errors:

      First time deployment after server startup :

      Caused by: java.lang.NoClassDefFoundError: org/apache/commons/digester/ObjectCreationFactory
       at org.apache.commons.digester.Digester.addFactoryCreate(Digester.java:2044)
       at org.apache.commons.digester.Digester.addFactoryCreate(Digester.java:1936)
       at org.apache.commons.digester.xmlrules.DigesterRuleParser.addRuleInstances(DigesterRuleParser.java:240)
       at org.apache.commons.digester.Digester.addRuleSet(Digester.java:1663)
       at org.apache.commons.digester.xmlrules.FromXmlRuleSet.addRuleInstances(FromXmlRuleSet.java:145)
       at org.apache.commons.digester.Digester.addRuleSet(Digester.java:1663)
       at org.apache.commons.digester.xmlrules.DigesterLoader.createDigester(DigesterLoader.java:91)
      


      I undeploy the .sar and redeploy it (without a server restart), different error is thrown:

      Caused by: java.lang.LinkageError: loader constraints violated when linking org/apache/commons/digester/ObjectCreationFactory class
       at org.apache.commons.digester.xmlrules.DigesterRuleParser.addRuleInstances(DigesterRuleParser.java:240)
       at org.apache.commons.digester.Digester.addRuleSet(Digester.java:1663)
       at org.apache.commons.digester.xmlrules.FromXmlRuleSet.addRuleInstances(FromXmlRuleSet.java:145)
       at org.apache.commons.digester.Digester.addRuleSet(Digester.java:1663)
       at org.apache.commons.digester.xmlrules.DigesterLoader.createDigester(DigesterLoader.java:91)
      



      I am not able to figure out why this is happening. But I did notice that "commons-digester.jar" is also bundled with "jbossweb-tomcat50.sar".

      Files :

      Service.java

      package digesterloadertest;
      
      import java.io.File;
      import java.io.FileInputStream;
      import java.io.InputStream;
      
      import org.apache.commons.digester.Digester;
      import org.apache.commons.digester.xmlrules.DigesterLoader;
      
      public class Service {
      
       public void setName(String name) {
       System.out.println("Setting name : " + name);
       }
      
       public void add(String name, String type) {
       System.out.println("Adding name : [" + name + "], type : [" + type + "]");
       }
      
       public static void main(String[] args) throws Exception {
       Digester digester = DigesterLoader.createDigester(new File("config/digester_rules.xml").toURL());
       digester.setUseContextClassLoader(true);
      
       InputStream inStream = new FileInputStream("config/xml_for_digester.xml");
      
       digester.parse(inStream);
      
       }
      }


      JBossService.java

      package digesterloadertest;
      
      import java.io.InputStream;
      import java.net.URL;
      
      import org.apache.commons.digester.Digester;
      import org.apache.commons.digester.xmlrules.DigesterLoader;
      import org.jboss.system.ServiceMBeanSupport;
      
      public class JBossService extends ServiceMBeanSupport implements JBossServiceMBean {
      
       public void startService() throws Exception {
       URL u = Thread.currentThread().getContextClassLoader().getResource("config/digester_rules.xml");
       Digester digester = DigesterLoader.createDigester(u);
       digester.setUseContextClassLoader(true);
      
       InputStream inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("config/xml_for_digester.xml");
      
       digester.parse(inStream);
       }
      }


      JBossServiceMBean

      package digesterloadertest;
      
      import org.jboss.system.ServiceMBean;
      
      public interface JBossServiceMBean extends ServiceMBean { }


      config/digester_rules.xml

      <?xml version="1.0"?>
      
      <digester-rules>
       <object-create-rule pattern="service" classname="digesterloadertest.Service"/>
       <set-properties-rule pattern="service">
       <alias attr-name="name" prop-name="name" />
       </set-properties-rule>
       <call-method-rule pattern="service/sub-service" methodname="add" paramcount="2"/>
       <call-param-rule pattern="service/sub-service" paramnumber="0" attrname="name"/>
       <call-param-rule pattern="service/sub-service" paramnumber="1" attrname="type"/>
      </digester-rules>


      config/xml_for_digester.xml

      <?xml version="1.0"?>
      
      <service name="MyService">
       <sub-service name="SubService1" type="Any"/>
       <sub-service name="SubService2" type="Some"/>
       <sub-service name="SubService3" type="All"/>
      </service>


      Any help on this would be of great help.

      Thanks