Maven does not directly support some libraries, like Microsoft’s SQL Server JDBC. This tutorial will show you how to add an external dependency to your local Maven repository. It assumes you have already installed Maven.

Download the JDBC driver for Microsoft SQL Server

  1. Visit the MSDN site for SQL Server and download the latest version of the JDBC driver for your operating system.
  2. Unzip the package
  3. Open a command prompt and switch into the expanded directory where the jar file is located.
  4. Execute the following command. Be sure to modify the jar file name and version as necessary:
  5. mvn install:install-file -Dfile=sqljdbc4.jar -Dpackaging=jar -DartifactId=sqljdbc4 -Dversion=4.0
  6. You should see something similar to this:
  7. [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Maven Stub Project (No POM) 1
    [INFO] ------------------------------------------------------------------------
    [INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ standalone-pom ---
    [INFO] Installing /Users/claude/installers/JDBC/sqljdbc_4.0/enu/sqljdbc4.jar to /Users/claude/.m2/repository/com/microsoft/sqlserver/sqljdbc4/4.0/sqljdbc4-4.0.jar
    [INFO] Installing /var/folders/c6/q1bdtq557kv54783p1g6cbsw0000gp/T/mvninstall1874482299687761721.pom to /Users/claude/.m2/repository/com/microsoft/sqlserver/sqljdbc4/4.0/sqljdbc4-4.0.pom
    [INFO] ------------------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.208s
    [INFO] Finished at: Tue Mar 13 14:07:31 EDT 2012
    [INFO] Final Memory: 3M/81M
    [INFO] ------------------------------------------------------------------------

    Modify your POM

    Include the new dependency by modifying your project’s pom.xml. Add the following dependency:


    Save the pom.xml file and build the project to make sure no errors exist.

This article has 10 comments

  1. Róbert

    Thanks a lot for the howto, but you did not check that stuff for the pom.xml before pasting it, right? groupId and artifactId are spelled with a capital i.

  2. Claude

    You are welcome. And you are absolutely right, those properties were not in the correct case. They are correct now.

  3. Gurvinder

    My code was working fine with MySQL. I replace dependency for MSQL and made required change in rest of code for Connection URL etc.
    When I am trying to run my program, I am getting following error:

    Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
            at Source)
            at Source)
            at java.util.jar.JarVerifier.processEntry(Unknown Source)
            at java.util.jar.JarVerifier.update(Unknown Source)
            at java.util.jar.JarFile.initializeVerifier(Unknown Source)
            at java.util.jar.JarFile.getInputStream(Unknown Source)
            at sun.misc.URLClassPath$JarLoader$2.getInputStream(Unknown Source)
            at sun.misc.Resource.cachedInputStream(Unknown Source)
            at sun.misc.Resource.getByteBuffer(Unknown Source)
            at Source)
            at$000(Unknown Source)
            at$ Source)
            at Method)
            at Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: org.feed.JAXBUnmarshaller. Program will exit.
  4. Claude

    It doesn’t look like your exception relates to the JDBC change. org.feed.JAXBUnmarshaller could not be found.

  5. Mejnar

    I’m not sure this is the way to do it. This will add those artifacts to your local workstation’s repository. I would say only to use the method described here as your absolutely LAST resort.

    Maven is all about consistency. If there’s more than one developer working on the project he/she should get the same downloaded artifacts as you do.

    The correct, but somewhat cumbersome, solution is to upload such artifacts to your company-wide Maven repository where there’s already a place for that called “3rd part library repo”. Yes, this requires that you run such a company-wide Maven Repository Manager. There’s Archiva, Artifactory and Nexus to choose from.

  6. Claude

    The ideal development environment, especially a corporate one with many developers, requires an internal repository for artifacts not available on the central repository.

    This example is a solution for those lone developers who need to add a dependency that is not open source and don’t have a corporate repository.

  7. Krishna Kumar Chourasiya

    I have successfully executed command to save sqljdbc4.jar file into .m2 (local repository). But when I was trying to add dependency at the pom it is still showing me “Missing artifact”. 

    Any help greatly appreciated.


  8. Claude

    There isn’t a whole lot of room for error when loading the driver in Maven or using it in your project’s POM. You need to make sure the file name, groupId, artifactId and version are correct for your file.

    Feel free to reply with the installation command you used, its output and your POM dependency for review.

Comments are closed.