6 Replies Latest reply on Oct 29, 2003 8:52 AM by arabin

    jboss321 deployment order : duplicate class definition

    rme

      I've got a base jar file and then a couple of ejb jars that use the base jar.
      If I name the base jar with a name that is lexographically earlier than
      the other ejbs then everything is ok .... but what a hack (and what if
      some other engineer does not know to name all other ejb jars
      lexographically later).
      I have tried to use the manifest extionsion mechanism - jboss seems to
      ignore it (see j2ee spec page 124 for an example).

      If some other ejb loads first, then I end up with an error message:
      java.lang.LinkageError: duplicate class definition: <some class file>

      what is the correct, jboss, way of specifying load order between a base,
      utility jar, and the ejb's that depend upon it.

      thanks

      Richard

        • 1. Re: jboss321 deployment order : duplicate class definition

          Have you found any answers? I'd be interested in hearing them.

          First I would guess that you're packaging too much stuff into your EJBs. Correct me if I'm wrong, but you've got common classes used across multiple EJBs, so packaging should really be
          EJB.jar -- ejb classes only (more or less)
          .jar -- common app classes

          deployed in an EAR and referenced via a ClassPath entry in the Manifest.MF file, as the theory goes. Yes? did that solve your problem?

          I'm running into a problem where I'm deploying 2 apps based on the same common JAR - both deployed via EAR - and I also get the

          java.lang.LinkageError: duplicate class definition:

          I thought that JBoss deployed each application with its own ClassLoader? Didn't expect this error.

          Kent

          • 2. Re: jboss321 deployment order : duplicate class definition
            lightbeer

            We're suffering from this too. One approach we took was to specify the jar load order in the user-service.xml



            but this also seems hacky. Has anybody got the 'right' answer to this?

            • 3. Re: jboss321 deployment order : duplicate class definition
              ioparra

              1) I don't think the CLASSPATH entries in the manifest files has ever been considered as a tool for hot deployment. The only time I've seen it work(304,306,321) is only in an EAR. Deployment ordering(except for the classpath reference in the -service.xml), is dictated by the URLComparator in conf/jboss-service.xml. (sar,service.xml,rar,jar,war,wsr,ear,zip,*--- in that order).

              2) I solved this problem by changing the DeploymentSorter to PrefixDeploymentSorter. This sorter should deploy everything else as normal, but files that have numbers prefixing them will be deployed in that order. IE. All of Jboss' services will be deployed first, then 1persistance.jar, 2session.jar, 3web.war,4my-service.xml(in that order).

              I recommend this strategy only for development. In a production/release environment, I'd recommend the packaging in an EAR and specifying the CLASSPATH entries in each component to guarentee ordering.

              Let me know if this works out.
              -Ivan

              I've found that specifying the ordering in the user-service.xml, I get alot of duplicate class on JBoss321. Did you get the same result?

              • 4. Re: jboss321 deployment order : duplicate class definition
                darthtux

                I had the same problem a long time ago ... I did some research and to be honest I gave up ... :o)
                But it won't harm to share the results of my little study.

                If you pack everything in one ear there's no problem. If you reference a jar via the ClassPath entry in the manifest.mf file that jar file is loaded by an UCL that uses a unified loader repository. Now a guess ... Every class resource is loaded in the same repository which leads to duplicate classes, ClassCastExceptions, etc....
                The solution for this is to create a file jboss-app.xml. For example ...
                <jboss-app> <loader-repository>www..be:loader=something.ear</loader-repository> <loader-repository-config>java2ParentDelegation=true</loader-repository-config>
                </jboss-app>
                Now you use a different repository for every ear. Which works really well.

                Of course I wanted os deploy different ears ... The problem I encountered was the in one ear I bind(JNDI) a class to a name ... then when I want to ask that class I cannot load it because I use a different classloader. Does anyone how to solve this ....

                • 5. Re: jboss321 deployment order : duplicate class definition
                  pazu

                  Now, why the hell JBoss defaults to using a single class loader for all applications deployed is completly beyond my reason. This brings in tons of ClassCastExceptions or LinkageErrors when, for example, you have multiple applications using struts and all of them keep their own copy of the struts jar file.

                  • 6. Re: jboss321 deployment order : duplicate class definition
                    arabin

                    I'd like to know how I need to organize my classes and .jar files.
                    I have a startup class A.class, that is used in user-service.xml for automatic startup. That means that I need to put my .jar file containing A.class into jboss-home\server\default\lib directory. Do I ALSO need to put it into jboss-home\server\default\deploy directory? Or just in one place - jboss-home\server\default\lib?
                    This class uses class B.class. Where should the .jar file, containing B.class, be located?
                    Should it be located in jboss-home\server\default\lib or in jboss-home\server\default\deploy? Or in both?

                    Basically, .jar files with what exactly classes should be located in jboss-home\server\default\lib and .jar files with what exactly classes should be located in jboss-home\server\default\deploy?

                    Another question. I could have just one combined .jar file with all classes, located in both directories. Can I split it somehow? Am I allowed to have several .jar files under jboss-home\server\default\deploy? Under jboss-home\server\default\lib?
                    Can I split it to several .jar files? Where exactly do I put them? In both places?
                    For instance, I split it to two .jar files. Do I need to put both into both places?

                    Can I put several classes into several different .jar files? Like if I put A.class into both B.jar and C.jar into jboss-home\server\default\deploy, will I have any problems? Like trying to redeploy certain things twice? Like EJBs or Message Driven Beans?

                    Can you give me any explanations on those questions? I am definitely doing something wrong. At this point the only way I succeed is to put everything into ONE .jar file, and put it into both directories. I can live with it, but that is not what I want.

                    I do not want to duplicated files unnecessarily into two directories, and I do not want conflicts between different files, between EJBs and MDBs. But I want all my EJBs and MDBs to be deployed correctly. At the same time I want to put as small amount of files as possible into jboss-home\server\default\lib directory (moving the rest to jboss-home\server\default\deploy), and I also want to split my .jar file in jboss-home\server\default\deploy directory into several .jar files, related to different packages.

                    Please give my some kind of guidelines to do that. Thanks