6 Replies Latest reply on Feb 6, 2012 6:35 PM by sfcoy

    Jboss JDBC datasource using jar file in WEB-INF/lib instead of creating a new module

    ziggy25

      As i understand it, with JBOSS 7, the data source is configured by creating a new module in `$JBOSS_HOME/modules`. This process includes adding the jar file for the jdbc driver to be used by the datasourced to be configured.

       

      Is there any way i can configure a datasource without having to create a new module?

       

      My web application has the MySQL Connector JDBC driver in the war file (in `WEB-INF/lib` - Included as part of the maven build). Wouldnt creating a new module result is a class conflict as this requires copying the jar file in the `modules/../main/ folder`?

        • 1. Re: Jboss JDBC datasource using jar file in WEB-INF/lib instead of creating a new module
          sfcoy

          Why does the driver need to be in the WEB-INF/lib directory?

          • 2. Re: Jboss JDBC datasource using jar file in WEB-INF/lib instead of creating a new module
            ziggy25

            Because at the moment if i want to deploy the application on to any application server i just provide the war file and thats it. It can be deployed to Tomcat by just dropping it on to the webapps folder.

             

            I would like to avoid having to make any changes to it just so that it becomes deployable to Jboss. If i move it to the driver to the modules folder then it wont be deployable on other application servers.

             

            Also if it is not in WEB-INF/lib, the eclipse build path will also need to be updated to temporarily find the driver. Seems like a lot of hassle for something that was so simple.

            • 3. Re: Jboss JDBC datasource using jar file in WEB-INF/lib instead of creating a new module
              sfcoy

              Have you actually tried this on other "application servers"?

               

              I'm pretty sure that this won't work on WebSphere, WebLogic or Glassfish either (I have first hand experience with the first two).

              • 4. Re: Jboss JDBC datasource using jar file in WEB-INF/lib instead of creating a new module
                sfcoy

                ziggy ~ wrote:

                 

                ...

                Is there any way i can configure a datasource without having to create a new module?

                ...

                 

                JDBC 4 drivers can be deployed in JBoss AS 7.1 by just copying them into the "deployments" directory. No module setup is required.

                 

                I haven't tried it with MySQL, but this certainly works for PostgreSQL.

                • 5. Re: Jboss JDBC datasource using jar file in WEB-INF/lib instead of creating a new module
                  ziggy25

                  What is the reason that it does not work if it is in WEB-INF/lib?

                  • 6. Re: Jboss JDBC datasource using jar file in WEB-INF/lib instead of creating a new module
                    sfcoy

                    I've had a think about your original question:

                    Is there any way i can configure a datasource without having to create a new module?

                    According to the specs (EE5.17) you can define a datasource in your web.xml file:

                     

                    {code:xml}

                    <data-source>

                         <description>Sample DataSource definition</description>

                         <name>java:app/MyDataSource</name>

                         <class-name>com.foobar.MyDataSource</class-name>

                         <server-name>myserver.com</server-name>

                         <port-number>6689</port-number>

                         <database-name>myDatabase</database-name>

                         <user>lance</user>

                         <password>secret</password>

                         <property>

                              <name>Property1</name>

                              <value>10</value>

                         </property>

                         <property>

                              <name>Property2</name>

                              <value>20</value>

                         </property>

                         <login-timeout>0</login-timeout>

                         <transactional>false</transactional>

                         <isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>

                         <initial-pool-size>0</initial-pool-size>

                         <max-pool-size>30</max-pool-size>

                         <min-pool-size>20</min-pool-size>

                         <max-idle-time>0</max-idle-time>

                         <max-statements>50</max-statements>

                    </data-source>

                    {code}

                     

                    Presumably, this will use the driver classes from your WEB-INF/lib directory.

                     

                    I really don't know what Tomcat will make of this, but there's a good chance that it will work there too.