1

I have created project want to deploy it using Jenkins and Git. I created maven project and added all the dependencies required. My one of class contains following code-

try {
    DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
} catch(Exception e) {
    System.out.println("Problem registering JDBC driver");
}

and indicates error at com.microsoft.jdbc.sqlserver.SQLServerDriver() this line like not able to find com.microsoft package.

I have added maven dependency for Microsoft server driver in POM file-

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>6.4.0.jre8</version>
    <scope>test</scope>
</dependency>

Now when i try to run that project with clean install it gives error as:

package com.microsoft.jdbc.sqlserver does not exist

and fails the build.
What should I do to remove this error and run my project successfully?

2
  • did you update the project?maven->updateproject Commented Jun 28, 2018 at 6:10
  • 1
    You should not load a JDBC driver like that. Calling DriverManager.registerDriver is not for applications to be called, it is only for JDBC drivers to register themselves when loaded. If you need to load, then use Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver") and the driver will register itself. Commented Jun 28, 2018 at 6:53

1 Answer 1

1

You include the artifact with <scope>test</scope> but apparently use it in the main code.

Change the scope to compile or (if scope of this artifact is not managed elsewhere) simply remove <scope>test</scope>.

For the future, what helps with this kind of questions is to simply run:

mvn dependency:tree -Dscope=compile

You will see a tree of artifacts considered for the compilation.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.