aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Maven dependency for sql jdbc driver in pom.xml  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Maven dependency for sql jdbc driver in pom.xml  " Watch "Maven dependency for sql jdbc driver in pom.xml  " New topic
Author

Maven dependency for sql jdbc driver in pom.xml

Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 266
Hi All,

I want to add the dependency for sql jdbc driver. Following is the snippet which I have added in pom.xml

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

I then rt. click on my pom.xml and run maven:install

as expected the build fails and it gives the following error:
"Failed to execute goal on project queryutility: Could not resolve dependencies for project : Failure to find com.microsoft.sqlserver:sqljdbc4:jar:4.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]"

I even downloaded the sqljdbc4.jar and then manually pasted at the location: \.m2\repository\com\microsoft\sqlserver\sqljdbc4\4.0\

even now the build fails giving the above error.

Please do help me in resolving this error.

Thanks and Regards,
Sid.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2404
    
  28

Microsoft doesn't give permission to maven to host their JDBC driver in the maven repo. So, you will have to download the JDBC driver, and put it in your own repo
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Two things. First, add a scope tag to the dependency, you should require the JBDC driver only at runtime:



Second, copying the JAR into your local repository directory is not sufficient - Maven expects to find metadata information to locate a dependency. To properly install the JAR in your local repository, use the install-file target of the install plugin:

mvn install:install-file -Dfile=<path-to-jar-file> -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0

Maven 2.x used to provide this command line as part of the error message for a missing jar, which I found to be extremely handy; not sure why they stopped doing that in 3.x


JBoss In Action
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 266
Jayesh A Lalwani wrote:Microsoft doesn't give permission to maven to host their JDBC driver in the maven repo. So, you will have to download the JDBC driver, and put it in your own repo


I do understand that Microsoft doesn't give permission to maven to host their JDBC driver in the maven repo. Therefore I downloaded the sqljdbc4.jar and place it in the repository .m2
Then I ran the pom.xml. Also I would like to tell that I have downloaded the Maven plugin for Eclipse and run maven commands through eclipse. I rt. click on the pom.xml and click on maven install. There I get this error.

I downloaded the JDBC driver. But how do I put it in my own repo and use it ? Please do let me know the procedure.
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 266
Peter Johnson wrote:Two things. First, add a scope tag to the dependency, you should require the JBDC driver only at runtime:



Second, copying the JAR into your local repository directory is not sufficient - Maven expects to find metadata information to locate a dependency. To properly install the JAR in your local repository, use the install-file target of the install plugin:

mvn install:install-file -Dfile=<path-to-jar-file> -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0

Maven 2.x used to provide this command line as part of the error message for a missing jar, which I found to be extremely handy; not sure why they stopped doing that in 3.x



Sure, I would add the scope tag to the dependency in the pom.xml

I have installed maven plugin in eclipse so I run my maven commands through eclipse and not through command prompt. Could you please let me know how do i use the install-file target of the install plugin using Eclipse ? That would be extremely helpful.

Thanks and Regards,
Sid.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Um, getting eclipse to do this is probably more hassle than it is worth. Just run the command from a prompt.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maven dependency for sql jdbc driver in pom.xml