I have a very simple line of code that is called from an .xhtml file ( in a JSF 2.0 project ) which looks like:
try {
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception e) {
e.printStackTrace();
}
So in my C:\ folder I have the file: mysql-connector-java-5.1.24-bin. I have added this jar as an extenral jar in IntelliJ Idea 12.
When I start my application like this, I get the "Class not found exception." However, when I add this dependency to my pom.xml file:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
I get no exception and class is loaded fine.
Here is a screenshot:
The jar file I underlined with green is the Jar added externally from **File -> Project Structure -> Libraries **
The one I underlined with red is the jar file that is downloaded by maven.
My question is: Why do I get the Class not found exception, although I have added the Jar externally?
In case I require a Jar file that I will not be able to download via maven, what am I supposed to do?
One extra information: I created a sample Java project with one class only, and I added this external Jar file with the method I explained above. No maven, no tomcat, nothing. Just a simple main method. I ran this same code, and it worked fine. So it has to have something to do with IntelliJ and one or more of:
- Maven
- Tomcat ( Deploying a War file )
- Maven and Tomcat?
Edit: When I add the external Jar only and try importing a class from com.mysql.jdbc... IntelliJ IDEA does not come up with any warnings / errors. It finds the class, however after the deployment, it seems like the Class can not be found anymore.