Boris
Boris

Reputation: 586

IntelliJ can't find sqljdbc4.jar from Maven even though it resolves?

IntelliJ does not let me import com.microsoft even though Maven resolves the dependency and it appears as a Module in my project settings (thus should be in the classpath).

enter image description here

External dependency resolves: Modules: enter image description here

POM file has this:

<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>

I used the following to install sqljdbc driver (which I downloaded from MSDN) for Maven: http://techmajik.com/2014/04/24/how-to-setup-maven-dependency-for-microsoft-sql-server/

Upvotes: 2

Views: 7790

Answers (3)

user1554876
user1554876

Reputation: 324

The older sqljdbc driver (v 4.0) jar file is available at the maven repo : https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4/4.0

Download and install it using the command as mentioned by user4198625 taking care to

  • make sure that maven (mvn) in in your PATH
  • JAVA_HOME is correctly defined in your env variables (for Windows). This is expecially important if you are running the mvn batch file.
  • For the command to work as is, you need to execute it from the directory where the jar file is present.

Upvotes: 0

shivam srivastava
shivam srivastava

Reputation: 460

You can directly use this below dependency:

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version> </dependency>

Upvotes: 0

user4198625
user4198625

Reputation:

Try adding it directtly to Maven repository like this:

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

and then add this to your POM.xml

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

for more detailes you can read this topic:

http://claude.betancourt.us/add-microsoft-sql-jdbc-driver-to-maven/

You need to do this because SQL Server driver is not included in maven repository - and you need to install it yourself.

Upvotes: 1

Related Questions