Adding a Mysql JDBC driver

We might just download a JDBC implementation Jar file like mysql-connector-java-5.1.16.jar manually and add it to our (Eclipse) environment. If we want to share our project with other people or work on it on different workstations this jar file must be available on each system we are working with.

One solution might be to integrate it into our project completely (e.g. in a lib folder) and put the whole project under version control (Git, Svn). On the other hand this just bloats our project with external (library) dependencies.

Maven helps us to easily manage external dependencies. The idea is to keep them in centralized repositories for download and add meta information like a package name, a package group name and a version number for retrieval:

  1. Searching for mysql in a maven repository yields the Java JDBC™ connector:

  2. We choose the most recent version:

  3. Again we copy the dependency snippet ...

  4. ... and add it to our pom.xml file's dependency section:

  5. Did we actually succeed? Right-clicking on our project Build path Configure Build Path and choosing the Libraries tab we see our CLASSPATH being extended:

    Notice the location of the Mysql jar below the .m2 Maven folder in the user's home directory. If we share our project this location will change to e.g. c:\users\foo\.m2\... due to different system default paths.