6 Replies Latest reply on Feb 2, 2010 12:47 PM by peterj

    Question about adding a folder with classes to the CLASSPATH

    ranjix

      Hey guys, quick description (hopefully) and a question -

       

      basically I have a couple of j2ee apps which share a common piece of code ("core"). The folders are pretty much:

       

      - core

           - classes

                - com

                     - blabla

                          - someclasses.class

      - app1 (structure of an EAR)

           - META-INF

           - app1 war

           - app1 ejb

      - app2

           - similar to above

       

      What I want is to have the apps run from app1 and app2 folder (by adding the apps "roots" in server/conf/bootstrap/profiles.xml), and, in the same time, the apps to find the classes in core/classes folder. With other container is possible using the CLASSPATH env var (in Weblogic for example), or using "Shared Libraries" (in WebSphere, libraries.xml would have a classpath pointing to the core/classes).

       

      Any idea how could I achieve this in JBoss?

       

      Appreciate any answer,

       

      Ranjix

        • 1. Re: Question about adding a folder with classes to the CLASSPATH
          ranjix

          P.S. I should add something. The "shared" classes still need to be in their own classloaders, some of them are statics which would be different between app1 and app2...

           

          thanks

          • 2. Re: Question about adding a folder with classes to the CLASSPATH
            peterj

            So are you saying that you are maintaining these statistics in static variables, or that you are using singletons? If so, then you will need to inlcude the common classes in each EAR and define a classloader repository for reach EAR.

             

            The other otpion would be to not maintain any data in static or singleton object - then each EAR would have its own set of data objects maintining their own sets of data even if the command classes were packed in a JAR and placed in common/lib.

            • 3. Re: Question about adding a folder with classes to the CLASSPATH
              ranjix

              thanks for answer, Peter.

               

              I'll try to be more concrete, imagine a Database class which manages the database (what else) operations. This class will create a singleton per app (app1 Database and app2 Database will have different connections and so, to 2 different databases). In the same time, the WAR and the EJBs in each app will have to use the same Database instance (since they do work on the same database).

               

              What I want is an infrastructure which will allow me to add core/classes/../Database to both classpaths of the 2 apps. I want to be able to compile the class and have the apps bounce without restarting the server (hot redeployment), and I definitely want to have the folder in the classpaths, not a packaged jar.

               

              Hope that clarifies a little...

               

              thanks.

               

              P.S. refactoring the statics and replacing them with actual instances is not really a solution, the amount of code that needs to change is vast, and the database class is one of the many singletons in the apps...

              • 4. Re: Question about adding a folder with classes to the CLASSPATH
                peterj
                Since you are using singletons (you answered "yes" to the question in the first paragraph of my prior reply), the solution is in the second sentence of the first paragraph.
                • 5. Re: Question about adding a folder with classes to the CLASSPATH
                  ranjix

                  thanks Peter, I might have misread your first question "you are maintaining these statistics in static variables or ..."

                  The truth is that for the purpose of my question I hardly see any relevance if it's statics or singletons, since singletons (as a pattern) are implemented usually using statics. So, in any case, assuming that there is a subtle difference which I miss at this point, allow me to change the answer to your question by saying that yes, the Database class uses static variables, and is not a Singleton in a "design pattern" kind of way... Would this change your answer?

                   

                  Up to this point is pretty clear that I need separate classloaders for each EAR, and this classloader should be the one that loads the Database class (as per my example). The question remains if I can just add a folder with classes to the classpath of each app, or I still need to package them as a jar and copy them in the structure of the EAR of each app...

                   

                  thanks again

                  /Ranjix

                  • 6. Re: Question about adding a folder with classes to the CLASSPATH
                    peterj

                    Static or singleton, it doesn't matter. You are still stuck packaging the common classes in a JAR and including that JAR in both EARs and defining a classloader repository. Unless you place the JAR completely ouside of JBoss AS and write your own classloader.