[jboss-as7-dev] problem with the classloader, not able to load a JDBC driver

Flemming Harms flemming.harms at gmail.com
Mon Jul 23 11:42:41 EDT 2012


I found a solution to my problem. Had to update the xsd schema with an
extra attribute "module" and then user need pack his JDBC driver as module.

I use the code below to load the model and the driver class.

Class<?> driverClass =
Module.loadClassFromCallerModuleLoader(ModuleIdentifier.fromString(moduleName),
driver);
driverClass.newInstance();

<outbound-connections>
        <database>
            <connection module="com.h2database.h2"
driver="org.h2.jdbcx.JdbcDataSource" name="db"
url="jdbc:h2:/tmp/test;DB_CLOSE_DELAY=-1" username="sa" password=""
min-pool-size="10" max-pool-size="20" />
        </database>
</outbound-connections>

Does it make sense?

Thanks

2012/7/20 Flemming Harms <flemming.harms at gmail.com>

> Hi
>
> I'm trying to finish https://issues.jboss.org/browse/AS7-1371 but I ran
> into a problem with the class loader. I need way to load the class for a
> specified JDBC driver, but I can't seem to figure out how to make it
> available on the classpath too my authentication service.
>
> I try to load the connection class like this, and testing it with the
> existing H2 JDBC driver:
> ClassLoader original = null;
>         try {
>             original = Thread.currentThread().getContextClassLoader();
>             if (original != null) {
>                 Thread.currentThread().setContextClassLoader(null);
>             }
>             Class.forName(this.driver).newInstance();
>         } finally {
>             if (original != null) {
>                 Thread.currentThread().setContextClassLoader(original);
>             }
> }
>
> The user can setup a outbound connection to a database for authentication,
> by using the configuration below
>
>  <security-realm name="ManagementRealm">
>       <authentication>
>            <local default-user="$local"/>
>            <database connection="db" plain-text="true">
>              <!-- simple-select-users table="users" username-field="user"
> password-field="password"/ -->
>              <sql-select-users sql="select user,password from users where
> user = ?" />
>            </database>
>       </authentication>
> </security-realm>
>
> <outbound-connections>
>         <database>
>             <connection driver="org.h2.jdbcx.JdbcDataSource" name="db"
> url="jdbc:h2:/tmp/test;DB_CLOSE_DELAY=-1" username="sa" password=""
> min-pool-size="10" max-pool-size="20" />
>         </database>
> </outbound-connections>
>
> Any suggestions how to solve this?
>
> Thanks!
>
> br
> Flemming
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-as7-dev/attachments/20120723/1d63c228/attachment.html 


More information about the jboss-as7-dev mailing list