How to add SQL Server dependency in Maven?

6

I'm trying to add the dependency of SQL Server on my POM but gives Missing Artifact .

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc4</artifactId>
    <version>4.0</version>
    <scope>runtime</scope>
</dependency>

How can I resolve this problem?

    
asked by anonymous 03.07.2015 / 22:14

2 answers

8

This artifact is not loaded in Maven repositories online.

The solution is to download the Microsoft website library and add it to the < to the local maven repository, with the command:

mvn install:install-file -Dfile=sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar

Source: Missing artifact com.microsoft.sqlserver: sqljdbc4: jar: 4.0

If you use Maven through the Eclipse plugin, you will not be able to use the command line, and you must use the Eclipse interface itself to install the library in your local repository. As the tip of @ BrunoCésar in the comments, do the following:

Right-click the project name, go to "Run As > Run Configurations ..."

Inthewindowthatopens,rightclickon"Maven Build" then select "New".

Fillinthe"Goals" field with the command:

install:install-file -Dfile=D:\sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar

In the "-Dfile=" field, enter the full path of the file .jar .

Whenrunningthecommand,ifallgoeswellyouwillseethemessage"BUILD SUCCESS":

Andpom.xmlwillnormallyacceptthedependencysqljdbc4,andwillnolongershowtheerror:

    
03.07.2015 / 22:25
-1

Another way to import such a dependency into your Eclipse project can be seen in the steps below.

  • Download the library from microsoft's official website. When extracting the contents of the file in question, you can find different libraries for each version of Java, for example: sqljdbc41.jar (JRE7) or sqljdbc42.jar (JRE8).
  • Right click on the project, select "Import" and click on the "Import" option.
  • Expand the Maven directory, select the "Install or deploy an artifact to a Maven repository" option and click "Next."

  • Fill in the fields as shown:

  • Artifact file: path to the directory of the previously downloaded library. Ex: D: \ lib \ sqljdbc42.jar or /Volumes/FILES/lib/sqljdbc42.jar. Group id: com.microsoft.sqlserver% Artifact id: sqljdbc4% Version: 4.2 > Packaging: jar

  • Now add a new dependency between the TAGs of the Maven pom.xml file in your project.
  • <dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc4</artifactId>
    <version>4.2</version>
    </dependency>
    
  • Finally, update your project and the dependency will load successfully!
  • 21.02.2017 / 17:24