How to add SQL Server dependency to Maven?

Asked

Viewed 7,676 times

6

I’m trying to add dependency on SQL Server in 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 solve this problem?

2 answers

8


This artifact is not loaded in the online Maven repositories.

The solution is to download the microsoft website and manually add it to your 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 cannot use the command line, and you must use the Eclipse interface itself to install the library in your local repository. As per @Brunocésar’s tip in the comments, do the following:

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

inserir a descrição da imagem aqui

In the window that opens, right-click on "Maven Build" then select "New".

inserir a descrição da imagem aqui

Fill in the "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 file path .jar.

inserir a descrição da imagem aqui

When running the command, if all goes well you will see the message "BUILD SUCCESS":

inserir a descrição da imagem aqui

And pom.xml will normally accept the dependency sqljdbc4, and will no longer show the error:

inserir a descrição da imagem aqui

  • Is this command at the same prompt or elsewhere? I have to be inside the directory that is the . sql server jar?

  • It can be at the same prompt, you have to have set the variable paths correctly. It has to be in the same folder as . jar, but that folder could be any one.

  • I don’t think I have Maven configured in the environment variables. I will give a search to configure it

  • Here you teach how to configure: http://www.mkyong.com/maven/how-to-install-maven-in-windows/

  • The problem is I don’t know where my Maven folder is because I downloaded it from Eclipse kk

  • Good doubt. I’ll look here too.

  • 1

    @Techies you can run by Maven Embedded eclipse also if you do not want to install it. Just go to Run Configurations > Maven Build, right click on, New and in Goals include this, as @Math said: install:install-file -Dfile=D:\sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar. Put a full path by guarantee =)

  • Goals does not appear here

  • I installed Maven again and used the command and it worked, thanks

  • 1

    @Techies just did a test with Maven from Eclipse and I was able to do it according to Bruno César’s information. Actually when you install the Maven plugin there is no mvn.exe anywhere, you have to do it through the Eclipse interface. But since you already solved your problem, then blz :)

  • All right, I got it here too both ways. Thanks for the help

  • 1

    @Math, I believe that answer is dated: https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4 I just tested it on my machine and it worked

  • 1

    @Jeffersonquesado verdade, now it can be done in an easy way, I will edit the answer to be generic for cases similar to this

  • 1

    @Jeffersonquesado I did not forget no, I just missed to stop to create a better example, have to give a good modified answer so I have to stop to do just this, I’ll see if I do tomorrow

Show 9 more comments

-1

Another way to import such dependency on your Eclipse project can be seen by the steps below.

  1. Lower the library from the official microsoft website. When extracting the contents of the file in question, it is possible to find different libraries for each version of Java, for example: sqljdbc41.jar (JRE7) or sqljdbc42.jar (JRE8).
  2. Right-click on the project, select "Import" and click on "Import" option".
  3. Expand the Maven directory, select the option "Install or deploy an Artifact to a Maven Repository" and click "Next".

  4. Fill in fields as an example:

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

  1. Now just include a new dependency between the TAG’s of the Maven pom.xml file in your project.
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.2</version>
</dependency>
  1. To finish, update your project and the dependency will be loaded successfully!
  • If the idea is to use Maven, lowering the lib only masks the problem. Furthermore, another project user would need to do these same manual procedures.

  • Unfortunately Microsoft did not provide such a library in an official Maven repository and the only option we have is to include it manually. The post I did is to solve the user problem, but it cannot be considered as a wrong use. If you have a solution other than the one I informed, please share with us.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.