执行mvn install报错:JDBC Driver未配置,求JDK/类路径配置指导
Hey there, let's work through this JDBC driver issue you're hitting when running mvn install with your MSSQL 2017 setup. I’ve dealt with similar headaches before, so here’s a step-by-step breakdown of how to fix it:
First, a quick clarification: there’s no official JDK version that comes pre-packaged with the MSSQL JDBC Driver—we’ll need to configure it manually. Below are the most reliable methods, ordered by recommendation:
Method 1: Add the Driver as a Maven Dependency (Highly Recommended)
This is the cleanest, most maintainable approach—no need to modify your JDK or system classpath. Just add the following dependency to your project’s pom.xml:
<dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> <version>12.4.1.jre11</version> <!-- Match this to your JDK: use 8.x.x.jre8 for JDK 8, 11.x.x.jre11 for JDK 11, etc. --> <scope>runtime</scope> </dependency>
- Double-check the version compatibility: Make sure the driver version aligns with your JDK release (e.g., JDK 8 uses driver versions starting with
8.). - After adding this, run
mvn clean installagain—Maven will automatically download the driver to your local repository and resolve the dependency gap.
Method 2: Place the Driver in the JDK Extension Directory
If you specifically need to add the driver to your JDK installation for global access:
- Download the correct MSSQL JDBC Driver jar file (e.g.,
mssql-jdbc-12.4.1.jre11.jar) from Microsoft’s official source. - Locate your JDK installation folder:
- For JDK 8 and earlier: Navigate to
jdk/jre/lib/ext - For JDK 11+: Go to
jdk/lib/ext(since JDK 11 removes the separate JRE directory)
- For JDK 8 and earlier: Navigate to
- Copy the downloaded jar file into this
extdirectory. - Restart your IDE or command line terminal to ensure the classpath picks up the new driver.
Note: This makes the driver available to all projects using this JDK, but it’s not ideal—it makes your project dependencies opaque, and you’ll run into issues if you switch to a different JDK later.
Method 3: Configure a Local Jar Dependency (If Central Repository Access Is Blocked)
If you can’t download the driver from Maven Central due to network restrictions:
- Download the driver jar to a local folder (e.g.,
~/local-maven-jars/). - Either:
- Add a local repository entry to your
settings.xml:<localRepository>~/local-maven-jars/</localRepository> - Or add a system-scoped dependency to your
pom.xml:<dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> <version>12.4.1.jre11</version> <scope>system</scope> <systemPath>/full/path/to/your/mssql-jdbc-12.4.1.jre11.jar</systemPath> </dependency>
- Add a local repository entry to your
This works, but it’s less flexible than Method 1, so use it only as a last resort.
Quick Additional Checks
- Verify that TCP/IP protocol is enabled for your MSSQL 2017 server (check via SQL Server Configuration Manager).
- Ensure your
settings.xmldoesn’t have mirror or repository configurations that block Maven from downloading the driver. - Run
mvn dependency:treeto inspect your project’s dependency tree and confirm the MSSQL driver is being pulled in.
If you’re still getting errors, sharing the exact error log would help pinpoint the issue—but following these steps should resolve most missing JDBC driver problems.
内容的提问来源于stack exchange,提问作者uma

