Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Getting java.lang.ClassNotFoundException: com.mysql.jdbc.Driver while connecting to external MYSQL database

Vinutha Vasan September 8, 2011

Hi All,

I have written a plugin which read data from external mysql database.

I have copied the "mysql-connector-java-5.1.10-bin.jar" jar to 'jira\webapp\WEB-INF\lib' folde on my plugin enevironmet directory.

But while executoing the plugin i am getting ClassNotFoundException exception for com.mysql.jdbc.Driver.

Please find the stack trace below,

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:772)
at org.apache.felix.framework.ModuleImpl.access$200(ModuleImpl.java:73)
at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1690)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.microchip.jira.plugins.versionManagement.dao.DatabaseValuesViewHelper.<init>(DatabaseValuesViewHelper.java:43)
at com.microchip.jira.plugins.versionManagement.restservice.VersionManagementResource.updateLineageData(VersionManagementResource.java:725)
at com.microchip.jira.plugins.versionManagement.restservice.VersionManagementResource.createIpVersion(VersionManagementResource.java:651)
at com.microchip.jira.plugins.versionManagement.action.AddIpProject.doExecute(AddIpProject.java:506)
at webwork.action.ActionSupport.execute(ActionSupport.java:165)
at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:76)
at webwork.interceptor.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:39)

Could any let me know what should i do to fix it?

Is that i sould set it to classpath explicitly? Is not this jar will be accessible from 'jira\webapp\WEB-INF\lib' folder?

Thanks,

Vinutha

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Wojciech Seliga
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 8, 2011

Hi,

JIRA comes with JDBC drivers located in <insatllation-dir>/lib. IIRC due to licensing requirements, SDK does not include this libraries (that's why you are putting them to WEB-INF/lib). But that two different locations wrt classloaders.

How we handle it in JIRA Importers Plugin:


...
import com.atlassian.core.util.ClassLoaderUtils;
...
private Driver loadDriver(final String driverName) throws SQLException {
try {
final Class clazz = ClassLoaderUtils.loadClass(driverName, JdbcConnection.class);
return (Driver) clazz.newInstance();
} catch (ClassNotFoundException e) {
throw new SQLException("JDBC driver class not found: " + driverName, e);
} catch (Exception e) {
throw new SQLException("Cannot instantiate JDBC driver class " + driverName + ": " + e.getMessage(), e);
}
}
...

Then to streamline dev process we have a special test profile in our pom.xml (not used when releasing a plugin):

...
<profiles>
<profile>
<id>test</id>
<activation>
<property>
<name>environment</name>
<value>test</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.13</version>
<scope>runtime</scope>
</dependency>
</dependencies>
...
</profile>

I hope it helps.

Cheers,
Wojtek

Vinutha Vasan September 8, 2011

Hi Wojciech,

Yes, It sovled my problem. Thank you.

Cheers,

Vinutha

TAGS
AUG Leaders

Atlassian Community Events