Reputation: 995
I am using IntelliJ IDEA. I have one sample Java code which requires MySQL driver class using class.forName();
to get database connection. It is a standalone Java application. When I run the main method of that class, I get ClassNotFoundException
. But, I have that sample code in a Maven project in which MySQL jar is configured. What am I missing? Eclipse does the job.
Upvotes: 1
Views: 4016
Reputation: 2674
There are different scope for maven import
<scope>provided</scope>
Check. Scope should not be provided.
Upvotes: 0
Reputation: 995
Thank you for your kind answers. I found that the maven dependency is scoped to 'provided'. So, Intellij IDEA
was not looking out for that jar because of the scope. When I changed the scope to compile(no scope tag)
, it is working fine. But without any change the configuration worked fine in Eclipse
.
Upvotes: 2
Reputation: 52774
Add these lines to Manven dependencies:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
And checklist:
- %M2_HOME%
- .m2
directory existing.
- Check internet connection.
- Check enabling Maven plugin inside IntelliJ IDEA.
- Add MySQL ConnectorJ jar file to lib
inside application server.
Upvotes: 0