SonarSource/sonarqube · error · MessageException

Directory does not contain JDBC driver:

Error message

Directory does not contain JDBC driver: 

What it means

After confirming the JDBC driver directory exists, driverPath lists *.jar files in it (non-recursively). If the directory contains no JARs, a MessageException 'Directory does not contain JDBC driver: <path>' is thrown. For the SQLSERVER provider it is also thrown when no file named mssql-jdbc* is present.

Source

Thrown at server/sonar-main/src/main/java/org/sonar/application/config/JdbcSettings.java:88

      props.set(JDBC_ADDITIONAL_LIB_PATHS.getKey(), libPathsToBeAddedToClasspath);
    }
  }

  private static List<String> additionalMsSqlLibPaths(File homeDir) {
    File dir = new File(homeDir, Provider.SQLSERVER.path);
    List<File> files = new ArrayList<>(FileUtils.listFiles(dir, new String[] {"jar"}, false));
    return files.stream().filter(f -> !f.getName().startsWith("mssql-jdbc")).map(File::getAbsolutePath).toList();
  }

  String driverPath(File homeDir, Provider provider) {
    String dirPath = provider.path;
    File dir = new File(homeDir, dirPath);
    if (!dir.exists()) {
      throw new MessageException("Directory does not exist: " + dirPath);
    }
    List<File> files = new ArrayList<>(FileUtils.listFiles(dir, new String[] {"jar"}, false));
    if (files.isEmpty()) {
      throw new MessageException("Directory does not contain JDBC driver: " + dirPath);
    }
    if (files.size() > 1 && Provider.SQLSERVER != provider) {
      throw new MessageException("Directory must contain only one JAR file: " + dirPath);
    } else if (Provider.SQLSERVER == provider) {
      return files.stream().filter(f -> f.getName().startsWith("mssql-jdbc")).findFirst()
        .orElseThrow(() -> new MessageException("Directory does not contain JDBC driver: " + dirPath)).getAbsolutePath();
    }
    return files.get(0).getAbsolutePath();
  }

  Provider resolveProviderAndEnforceNonnullJdbcUrl(Props props) {
    String url = props.value(JDBC_URL.getKey());
    Integer embeddedDatabasePort = props.valueAsInt(JDBC_EMBEDDED_PORT.getKey());

    if (embeddedDatabasePort != null) {
      String correctUrl = buildH2JdbcUrl(embeddedDatabasePort);
      warnIfUrlIsSet(embeddedDatabasePort, url, correctUrl);
      props.set(JDBC_URL.getKey(), correctUrl);

View on GitHub (pinned to 184c821202)

Solutions

  1. Place the JDBC driver JAR into the configured directory
  2. For SQL Server, ensure the JAR filename starts with 'mssql-jdbc' (e.g. mssql-jdbc-12.4.2.jre11.jar)
  3. Verify the JAR extension is lowercase '.jar'
  4. Re-download the driver if the archive was extracted incompletely

Example fix

// before: empty or wrong-named jar
cp sqljdbc4.jar $SONARQUBE_HOME/extensions/jdbc-driver/mssql/
// after
cp mssql-jdbc-12.4.2.jre11.jar $SONARQUBE_HOME/extensions/jdbc-driver/mssql/
Defensive patterns

Strategy: validation

Validate before calling

File[] jars = dir.listFiles((d, n) -> n.toLowerCase().endsWith(".jar"));
if (jars == null || jars.length == 0) throw new IllegalStateException("No driver JAR in " + dir);
if (isSqlServer && Arrays.stream(jars).noneMatch(j -> j.getName().startsWith("mssql-jdbc"))) throw new IllegalStateException("No mssql-jdbc JAR");

Type guard

static boolean hasDriverJar(File dir) { File[] f = dir.listFiles((d, n) -> n.endsWith(".jar")); return f != null && f.length > 0; }

Try / catch

try { jdbcSettings.start(); } catch (MessageException e) { if (e.getMessage().contains("does not contain JDBC driver")) { downloadDriver(); } throw e; }

Prevention

When it happens

Trigger: Configured driver directory exists but is empty; for Provider.SQLSERVER, the directory contains JARs but none starting with 'mssql-jdbc'.

Common situations: Downloading a driver but forgetting to copy it into extensions/jdbc-driver/<db>; extracting only part of a driver archive; using an older SQL Server JAR name (sqljdbc4.jar) that doesn't match the mssql-jdbc prefix.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/1693566051bbdec2. Report an issue: GitHub.