安装SQL Server驱动到Maven仓库

 

   我的问题:

   在公司项目中使用到sqlserver 2008 ,而公司管理项目架构用的是maven,所以需要导入相应的jar包,但是在maven中央仓库,找到了第三方 jtds  jar 1.3.1(JDK 1.7.X)与项目jdk不一致,所以抛出异常,

java.lang.UnsupportedClassVersionError: net/sourceforge/jtds/jdbc/Driver : unsupported classversion 51.0 (unable to load class net.sourceforge.jtds.jdbc.Driver)

 

51.0 --> jdk 1.7

 

原本认为只能使用maven 中央库提供的 sqlserver jdbc 的 jar包(第三方),官方的配置如下,貌似也可以!

我的做法是使用了 jtds-1.2.6.jar包,但这个官方的还是mark下!

 

转载:

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:
mvn  install : install - file  -Dfile=sqljdbc4.jar -Dpackaging=jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0
 
You should see something similar to this:
[INFO] Scanning  for  projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[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] BUILD SUCCESS
[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:

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

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

你可能感兴趣的:(安装SQL Server驱动到Maven仓库)