Do the jars in question appear in both the war file and the module?
yes.. same jars are in module and the war
1. Please post the entire exception stacktrace
2. As Steve hinted, you shouldn't have to package the database driver jars within your application. So getting rid of those jars from the .war should help, if what we are guessing is indeed the problem.
I am getting classcast exception for same class which verifies its due to different classloaders for same jar. For this scenario, the same jar is put in module and war.
I cant remove the jars from module or war. The war uses some of its classes so I have the dependency on both sides , in modules as well as in war.
Is it possible to have a single classloader for both module and war??
Please do post the exact exception stacktrace. There's no point trying to guess what we are helping you with.
The Driver will look like:
The connection is called com.jdbc.NonJdbcConnection
And those are in a file called NonJdbcDriver.jar
I have created a module as:
Under folder com/test/main, I have put the NonJdbcDriver.jar.
This jar will be used to create datasource.
Following code I am using to invoke the datasource:
DataSource ds = (DataSource)initContext.lookup("java:jboss/datasources/ExampleDS");
Connection con = ds.getConnection();
The connection we received is an instance of WrappedConnection. This connection, we are unwrapping as:
Connection conwrap = ((WrappedConnection)con).getUnderlyingConnection();
The getUnderlyingConnection() method will give us NonJdbcConnection Object. To use it as NonJdbcConnection, we need to cast it as :
NonJdbcConenction con = (NonJdbcConnection)conwrap
At this point the we get a classcast exception saying:
ClassCastException: Cannot cast com.jdbc.NonJdbcConnection to com.jdbc.NonJdbcConnection
I tried to see the classloaders for "conwrap" and NonJdbcConnection. Although both are same classes but have different classloaders which gives this error.