5 Replies Latest reply on Jan 17, 2011 2:03 PM by ohadze

    Linkage Error with Weld in two jars (Jboss 6 Final)

    ohadze

      Hi all,


      I've been trying some examples of Weld within Jboss 6.0 Final as a POC for my project. Since our app runs with several EAR files, I've split the Translator example from the Weld examples repository into two EARs. When only one of the EARs contain beans.xml everything seems to work fine. However, when I add beans.xml file to the other EAR (it only has a ejb-jar file, no WAR), JBoss fails to load, giving the following error:


      ...



      Caused by: java.lang.LinkageError: loader (instance of  org/jboss/classloader/spi/base/BaseClassLoader):
        attempted  duplicate class definition for name:
        "org/jboss/weld/examples/translator/web/org$jboss$weld$bean-jboss$classloader:id=
        "vfs:$$$users$oz$projects$weld-example$ear$target$weld-translator-web$ear"
        -NewSessionBean-TranslatorControllerBean_$$_WeldProxy"
          at java.lang.ClassLoader.defineClass1(Native Method)
          at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
          at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
          at java.lang.ClassLoader.defineClass(ClassLoader.java:466)
          at sun.reflect.GeneratedMethodAccessor129.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)l
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.jboss.weld.util.bytecode.ClassFileUtils.toClass2(ClassFileUtils.java:143)
          at org.jboss.weld.util.bytecode.ClassFileUtils.toClass(ClassFileUtils.java:109)





      I can provide the sample files, if required. Any help is greatly appreciated.

        • 1. Re: Linkage Error with Weld in two jars (Jboss 6 Final)
          alesj

          For some reason Weld is trying to define duplicate class.


          Can you debug/trace down which class is the culprit and which code is responsible for this duplication?

          • 2. Re: Linkage Error with Weld in two jars (Jboss 6 Final)
            alesj

            For some reason Weld is trying to define duplicate class.


            This is strange, specially since there is this check in Weld proxy creation code:


                     // First check to see if we already have this proxy class
                     proxyClass = cast(classLoader.loadClass(proxyClassName));
                  }
                  catch (ClassNotFoundException e)
                  {
                     // Create the proxy class for this instance
                     try
                     {
                        proxyClass = createProxyClass(proxyClassName);
            


            • 3. Re: Linkage Error with Weld in two jars (Jboss 6 Final)
              alesj

              Can you debug/trace down which class is the culprit and which code is responsible for this duplication?


              "org/jboss/weld/examples/translator/web/org$jboss$weld$bean-jboss$classloader:id=
                "vfs:$$$users$oz$projects$weld-example$ear$target$weld-translator-web$ear"
                -NewSessionBean-TranslatorControllerBean_$$_WeldProxy\"
              



              The class to be turned into proxy is org.jboss.weld.examples.translator.TranslatorControllerBean.


              But I still don't see (apart from some race condition) how you could get dup,
              since the proxy classname is unique wrt deployment name.

              • 4. Re: Linkage Error with Weld in two jars (Jboss 6 Final)
                ohadze

                I would be glad to. I am having trouble getting the source code into my IDE, though. Is there an easy way to get the source jar for the weld-core-no-jsf.jar (where the ClassFileUtils.class is located)? For some reason my IDE refuses to load the jars from the mvn repository...

                • 5. Re: Linkage Error with Weld in two jars (Jboss 6 Final)
                  ohadze

                  Hi Ales,


                  You must be right about the race condition, since as soon as I start debugging I get different errors - either LinkageError for different classes or a different deployment errors or, sometimes, no errors at all.
                  I'll keep trying and see where this leads.


                  Thanks.