I have a new application in Jboss using a .war file I’m trying to connect to MySQL DB at startup time (init method),
I have modified the standalone-sip.xml and added my driver following:
https://zorq.net/b/2011/07/12/adding-a-mysql-datasource-to-jboss-as-7/
In the startup logs I can see Driver and datasource are loading correctly:
23:19:30,565 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010404: **Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver** (version 5.1)
23:19:30,748 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "mysql-connector-java-5.1.22-bin.jar"
23:19:30,750 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010400: **Bound data source [java:jboss/datasources/opencall]**
23:19:30,933 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
23:19:30,954 INFO [org.jboss.as.osgi] (MSC service thread 1-1) JBAS011907: Register module: Module "deployment.mysql-connector-java-5.1.22-bin.jar:main" from Service Module Loader
But I see:
23:18:50,959 ERROR [stderr] (MSC service thread 1-5) java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module "deployment.opencall-2.1.0-SNAPSHOT.war:main" from Service Module Loader]
23:18:50,959 ERROR [stderr] (MSC service thread 1-5) at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
After that I see:
23:18:51,700 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS018559: Deployed "mysql-connector-java-5.1.22-bin.jar"
I believe problem is that my application is starting before mysql driver is loaded. But not sure how to force my app to use mysql driver during startup before is deployed. This is my code:
When I run it without Jboss it works fine, only when I deployed the war file fails.
try {
Class.forName(dbClass).newInstance();
} catch (InstantiationException e) {
logger.error("InstantiationException() Exception");
e.printStackTrace();
} catch (IllegalAccessException e) {
logger.error("IllegalAccessException() Exception");
e.printStackTrace();
}
if (dbPassword.equals(null))
dbPassword="";
Connection dbConnection = DriverManager.getConnection (dbUrl,dbUserName,dbPassword);
dbConnection.close();
Found this:
Is this a similar issue:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Added mysql in my maven dependencies (pom.xml) and then re- build