The Issue
Creating a JDBC connection pool in Netbeans 8.0 on a Centos 6.5 linux distribution resulted in a class not found exception.
1 |
java.lang.classnotfoundexception com.mysql.jdbc.jdbc2.optional.mysqldatasource |
This error occurs because Glassfish 4.0 bundled with Netbeans did not include the required JDBC driver.
The Solution
Download the MySQL connector driver by selecting the platform independent download. Select the compressed type of your choice (tar / zip). Extract the downloads content and look for the “mysql-connector-java-5.x.x-bin.jar” file. This is the file that Glassfish needs to properly load the MySQL datasource.
Place the jar file in the the following location
1 |
\PATH\TO\GLASHFISH\INSTALL\FOLDER\glassfish4.X.X\glassfish\lib |
After placing the jar file in the Glassfish lib folder restart the server. This should fix the class not found exception.