9 Replies Latest reply on Mar 9, 2011 2:48 AM by jaikiran pai

    JBoss AS 6 EAR issues with library directory

    Rick Herrick Newbie

      I have a project that we've been successfully deploying onto JBoss AS 5.1.0.GA for a while. It's in the EAR format and is pretty simple. It consists of a WAR file for the actual application, a PostgreSQL data source definition, and the PostgreSQL JDBC driver jar file.  The layout of the application is like this:

       

       

      • productweb.war
      • lib/postgresql-9.0-801.jdbc4.jar
      • META-INF/application.xml
      • META-INF/jboss-app.xml
      • META-INF/MANIFEST.MF
      • META-INF/maven/com.mycompany/productear/pom.properties
      • META-INF/maven/com.mycompany/productear/pom.xml
      • postgres-ds.xml

       

      The application.xml looks like this (I've snipped the namespace jazz in the <application> element for brevity):

       

      <?xml version="1.0" encoding="UTF-8"?>

      <application id="Application_ID" version="5" ...>

          <display-name>Product</display-name>

          <module>

              <web>

                  <web-uri>productweb.war</web-uri>

                  <context-root>/productweb</context-root>

              </web>

          </module>

          <library-directory>/lib</library-directory>

      </application>

       

      The jboss-app.xml looks like this:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE jboss-app PUBLIC "-//JBoss//DTD Java EE Application 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd">

      <jboss-app>

          <module>

              <service>postgres-ds.xml</service>

          </module>

      </jboss-app>

       

      Like I said, in JBoss AS 5.1.0.GA, this works fine. The server starts up, the JNDI data source in the postgres-ds.xml file is properly loaded, and the application can access the database through that.

       

      With JBoss AS 6, though, I get an error when the server tries to create the data source:

       

      16:31:11,389 INFO  [Version] Hibernate Validator 3.0.0.GA

      16:31:11,784 INFO  [AnnotationSessionFactoryBean] Building new Hibernate SessionFactory

      16:31:12,007 INFO  [ConnectionProviderFactory] Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider

      16:31:12,382 WARN  [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null: org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class: org.postgresql.Driver, url: jdbc:postgresql://localhost:5432/product_db)

       

      I can easily fix this by removing the jar from the EAR file and plopping it into the server/default/lib folder. When I do that, the data source is created smoothly (I run into some other errors after that, but I'm not certain it's related to this one), so it appears that the issue is that the PostgreSQL JDBC jar file is not getting picked up on the classpath of the application server.

       

      I tried removing the <library-directory> element entirely and putting the JDBC jar file in the root of the EAR archive but that gave me the same results. Ditto with changing the <library-directory> value to '/' with the jar at the root.

       

      Now, this construct worked previously, so why is it NOT working any more? I haven't been able to find anything in the JBoss AS 6 docs that speaks about the EAR packaging at all, so the operative docs still appear to be the JBoss AS 5 docs.  I've attached a sanitized version of the boot.log that's generated (the server.log contains literally nothing of interest: one thing I've really noticed that's a big change is that a lot of stuff that used to go into the server.log now goes into the boot.log).

       

      Any help or information on this would be great.

        • 1. JBoss AS 6 EAR issues with library directory
          Mark Paluch Master

          Hi Rick,

          have you tried to set Lib-Directory via jboss-app.xml?

           

           

          <?xml version='1.0' encoding='UTF-8'?>

          <!DOCTYPE jboss-app PUBLIC "-//JBoss//DTD J2EE Application 5.0//EN"

          "http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd" >

          <jboss-app>

          <library-directory>lib</library-directory>

          </jboss-app>

           

          Best regards,

          Mark

          • 3. JBoss AS 6 EAR issues with library directory
            Benjamin Seyinbour Expert

            1. I wouldn't bundle postgresql-9.0-801.jdbc4.jar with my EAR, better to drop it under 'server/default/lib' or even 'JBOSS_HOME/common/lib'

            2. Also, bettter to drop your 'postgres-ds.xml' under your server/default/deploy.

             

            Your postgres-ds.xml should look something like the following:

             

            <datasources>

              <local-tx-datasource>

                <jndi-name>jdbc/product_db</jndi-name>

                <connection-url>jdbc:postgresql://localhost:5432/product_db</connection-url>

                <driver-class>org.postgresql.Driver</driver-class>

             

             

            <metadata>

                     <type-mapping>PostgreSQL 8.0</type-mapping>

                  </metadata>

              </local-tx-datasource>

             

            </datasources>

             

            Right?

             

            Also:

             

            Don't forget to delete 'hsqldb-ds.xml' (under JBOSS_HOME/default/deploy) or rename it to (say) hsqldb-ds.xml.bak

            Also. make sure that there is no other copy od postgresql-x.x.jar hiding somewhere in JBOSSAS

             

             

            Cheer!

            • 4. JBoss AS 6 EAR issues with library directory
              Rick Herrick Newbie

              Benjamin,

               

              Regarding dropping the jar and data-source definition into the deploy folder, we're trying to minimize the need to fragment our installation. Thus if everything's wrapped up in one EAR file, all you have to do is drop that in and you're good to go. That lets us build the application from an aggregator Maven project that wraps everything up into the enterprise app archive. Like I said, this worked fine under 5.1.0.GA, including with the dependency packaged in the archive.

               

              Regarding the hsqldb-ds.xml definition, that can co-exist right along with any other data source definition, just so long as they have different jndi-name values specified. It's when you name your custom data source DefaultDS and leave the hsqldb-ds.xml in place that you get a conflict. Again, in 5.1.0.GA we had that same configuration (the hsqldb-ds.xml was left in place for testing purposes).

              • 5. Re: JBoss AS 6 EAR issues with library directory
                Rick Herrick Newbie

                Mark,

                 

                I don't remember where I found info on putting the <library-directory> directive into the application.xml, but after reading your suggestion about jboss-app.xml, I looked at the JBoss App 5 DTD and found this:

                <!-- An .ear file may contain a directory that contains libraries packaged in JAR files.

                The library-directory element of the .ear files deployment descriptor contains the name

                of this directory. If a library-directory element is not specified,

                the directory named lib is used.

                 

                An empty library-directory element may be used to specify that there is no library directory.

                 

                All files in this directory (but not subdirectories) with a .jar extension must be made available

                to all components packaged in the EAR file, including application clients.

                 

                   Used in: jboss-app

                -->

                So I tried just removing the <library-directory> element from application.xml, ran it again, and same end result. So that made me think a bit and I ran through a number of variations:

                 

                • In the application.xml both before and after the <module> element (in jboss-app.xml's DTD, the <library-directory> element MUST be before the <module> element)
                • In the jboss-app.xml before the <module> element
                • Leaving out the <library-directory> element altogether, since it should then use lib

                 

                I got the same result with all of them.

                 

                Also, I did set the folder name to lib instead of /lib, but same result.

                 

                And with all of it, if I just put the jar file in the server/default/lib folder, it works fine (well, up until the next error, which I think is caused by a change in how load-time weaving functions).

                • 6. JBoss AS 6 EAR issues with library directory
                  Benjamin Seyinbour Expert

                  Hi Rick,

                   

                   

                  It might fulfil your need to minimize the need for fragment, however the point remains  that JBoss comes with it loads of libraries. Duplicating them might cause you deployment problems  that you would least suspect it is caused by duplicate libraries. Aside from that,  say you are deploying two or more war/ear files, are you going to bundle copies of the same sets of libraries in each one of them rather than using just one set of copy?

                   

                  And what happens when there is a new version of the libraries? More inconvenience and work to fetch and upgrade each war/ear. In some applications where portability and space are design objectives. bundling (redundant) third-party libraries with such types of applications is out of the question.

                   

                   

                  The '<library-directory>" by default is "lib", therefore it is pointless re-stating it in the "application.xml" unless you are using a different name. This is why all your tests are showing the same  outcome.

                   

                  Cheers

                   

                  • 7. Re: JBoss AS 6 EAR issues with library directory
                    Rick Herrick Newbie

                    Yes, JBoss comes with loads of libraries and you need to know which ones regardless of whether you're going to package it in an EAR or put it in one of the lib folders. Class conflicts are class conflicts regardless of where the conflicting installed library is at. For example, v6 apparently has the JTA API library installed, whereas 5.1 didn't, since the first conflict I got trying to run my app on v6 was a conflict with javax/transaction/xa/XAResource. That was something that was just packaged in the WEB-INF/lib folder of the web app.  jta-1.1.jar and com.springsource.javax.transaction-1.1.0.jar were both getting pulled in on our build, which we hadn't noticed because it worked just fine (same versions anyways, so there's no real conflict, the second one in the classpath is just hidden by the first).

                     

                    Yes, if we want to upgrade just a library, that would be difficult. Given our customer base, that's likely not going to happen: because of acceptance, compliance, and integration requirements, we're actually better off packaging everything up for acceptance certification.  We're also looking at serving OSGi library bundles so that we can certify chunks and hot swap any dependencies that need to be changed out and upgraded.

                     

                    Finally, yes, the default library-directory is lib (I previously thought it was '/', which is why I specified it in the application.xml in the first place). And yes, my tests are showing the same outcome wih the jar in the lib folder, whether I specify library-directory explicitly or leave it off entirely. That's what you'd expect.

                     

                    However, the problem is that that outcome is application failure, which is not what's expected. That's the actual problem I'm trying to solve. So if you have any ideas why putting a jar into the lib folder in the EAR package ends up with the jar not being included on the application classpath, I'd be interested in hearing those.

                     

                    Thanks. I'm not trying to be snarky (although I'm obviously succeeding), but we have good reasons for why we want the libraries to be in the EAR. The libraries are not being found in the EAR and that's the problem, not how we should be packaging our application.

                    • 8. JBoss AS 6 EAR issues with library directory
                      Juergen Zimmermann Master

                      Declaring *-ds.xml as a service module is no problem as long as the JNDI name is ok. However, we place the JAR for a dtabase driver into $JBOSS_HOME/common/lib. This way it works fine.

                      • 9. Re: JBoss AS 6 EAR issues with library directory
                        jaikiran pai Master

                        Rick Herrick wrote:

                         

                        I can easily fix this by removing the jar from the EAR file and plopping it into the server/default/lib folder. When I do that, the data source is created smoothly (I run into some other errors after that, but I'm not certain it's related to this one), so it appears that the issue is that the PostgreSQL JDBC jar file is not getting picked up on the classpath of the application server.

                         

                        I tried removing the <library-directory> element entirely and putting the JDBC jar file in the root of the EAR archive but that gave me the same results. Ditto with changing the <library-directory> value to '/' with the jar at the root.

                         

                        Now, this construct worked previously, so why is it NOT working any more?

                        JDBC drivers were always expected to be placed in JBOSS_HOME/server/<servername>/lib folder and not be packaged in the application http://community.jboss.org/wiki/IWantToDeployMyOwnJdbcDriverInAScopedClassloader