SonarSource/sonarqube · error · MessageException

Directory must contain only one JAR file:

Error message

Directory must contain only one JAR file: 

What it means

For all providers except SQLSERVER, the driver directory must contain exactly one JAR file. If more than one .jar is present, driverPath throws MessageException 'Directory must contain only one JAR file: <path>' because it cannot decide which driver to load.

Source

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

  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);
      return Provider.H2;
    }

View on GitHub (pinned to 184c821202)

Solutions

  1. Remove all but one JDBC driver JAR from the directory
  2. Keep only the driver version matching your database
  3. Move auxiliary/dependency JARs to a different directory
  4. For multiple JAR needs, switch to the SQLSERVER provider path only if it is actually SQL Server

Example fix

// before
ls extensions/jdbc-driver/postgres  # postgresql-42.2.5.jar postgresql-42.7.3.jar
// after
rm extensions/jdbc-driver/postgres/postgresql-42.2.5.jar  # keep exactly one
Defensive patterns

Strategy: validation

Validate before calling

File[] jars = dir.listFiles((d, n) -> n.toLowerCase().endsWith(".jar"));
if (jars != null && jars.length > 1) throw new IllegalStateException("Multiple driver JARs in " + dir + "; keep exactly one");

Type guard

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

Try / catch

try { jdbcSettings.start(); } catch (MessageException e) { if (e.getMessage().startsWith("Directory must contain only one JAR")) { cleanupOldJars(); } throw e; }

Prevention

When it happens

Trigger: Dropping multiple JDBC JARs (e.g. an old and a new driver version) into the same driver directory for a non-SQLSERVER provider.

Common situations: Upgrading a driver by copying the new JAR alongside the old one; bundling driver plus helper JARs (e.g. shardingsphere or pooling libs) into the same folder.

Related errors


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