Search code examples
javamavenjdbcclassnotfoundexception

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver in Maven project


I'm trying to connect to a SQLServer DB using JDBC. I'm using jre 1.6 and I've added the 'sqljdbc/jar' to my class path on my OS. I've also added that jar far to my build path. When my code hits this line Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); it explodes. I can navigate to the class in the package explorer, I can also type out the namespace and eclipse intellisense picks it up as well, yet when it loads I get java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver. I'm using Eclipse Indigo Release 2 w/ Spring STS plugin, can any one tell me whats going on? btw: I can connect to my db using the DB using DB Explorer in Eclipse.


Solution

  • Thank you eveyrone for your suggestions, here is how I solved it:

    1. I added the jar in question to my .m2 repository folder

    2. Opened Pom.xml => clicked Dependencies Tab => clicked Add

    3. Modeled a folder structure to match that of that of the attributes that I entered. For example jdbc\sqljdbc4\4\sqljdbc4-0.jar (I added -0 as it needs to have a version #)*

    4. Rebuild, Deploy and BAM!