IntelliJ不允许我导入 com.microsoft ,即使Maven解析了依赖关系,它在我的项目设置中显示为模块(因此应该在类路径中)。
POM文件有:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.arcologydesigns.rest</groupId>
<artifactId>ads-webapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springexample Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<spring.version>4.0.5.RELEASE</spring.version>
<jdk.version>1.8</jdk.version>
<jackson.version>2.2.3</jackson.version>
<!--<sqlserver.version>4.2.6420.100</sqlserver.version>-->
<sqlserver.version>4</sqlserver.version>
<build.scm.revision>SCM_IDENTIFIER</build.scm.revision>
<build.number>BUILD_NUMBER</build.number>
<build.id>BUILD_ID</build.id>
<build.job.name>BUILD_JOB_NAME</build.job.name>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>${sqlserver.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20120521</version>
</dependency>
</dependencies>
<build>
<finalName>ads-webapp</finalName>
</build>
</project>
我使用以下命令为Maven安装sqljdbc驱动程序(我从MSDN下载):http://techmajik.com/2014/04/24/how-to-setup-maven-dependency-for-microsoft-sql-server/
答案 0 :(得分:1)
尝试将其直接添加到Maven存储库,如下所示:
mvn install:install-file -Dfile=sqljdbc4.jar -Dpackaging=jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0
然后将其添加到您的POM.xml
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
如需更多详细信息,请阅读以下主题:
http://claude.betancourt.us/add-microsoft-sql-jdbc-driver-to-maven/
您需要这样做,因为SQL Server驱动程序未包含在maven存储库中 - 您需要自己安装它。
答案 1 :(得分:0)
您可以直接使用以下依赖项:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version> </dependency>
答案 2 :(得分:0)
maven repo中提供了较旧的sqljdbc驱动程序(v 4.0)jar文件: https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4/4.0
使用user4198625提到的命令
下载并安装它