{"record":{"id":"dae3784083628cb6","repo":"SonarSource/sonarqube","slug":"cannot-detect-path-of-main-jar-file","errorCode":null,"errorMessage":"Cannot detect path of main jar file","messagePattern":"Cannot detect path of main jar file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java","lineNumber":145,"sourceCode":"    // supports decryption of values, so it must be used when values\n    // are accessed\n    return new Props(p);\n  }\n\n  private static void loadPropertiesFromEnvironment(System2 system, Properties properties, Set<String> overridableSettings) {\n    overridableSettings.forEach(key -> {\n      String environmentVarName = fromJavaPropertyToEnvVariable(key);\n      Optional<String> envVarValue = ofNullable(system.envVariable(environmentVarName));\n      envVarValue.ifPresent(value -> properties.put(key, value));\n    });\n  }\n\n  private static File detectHomeDir() {\n    try {\n      File appJar = new File(Class.forName(\"org.sonar.application.App\").getProtectionDomain().getCodeSource().getLocation().toURI());\n      return appJar.getParentFile().getParentFile();\n    } catch (URISyntaxException | ClassNotFoundException e) {\n      throw new IllegalStateException(\"Cannot detect path of main jar file\", e);\n    }\n  }\n\n  private static void warnOnNonSystemProperties(Properties fileProperties) {\n    Set<String> systemKeys = stream(ProcessProperties.Property.values())\n      .map(ProcessProperties.Property::getKey)\n      .collect(Collectors.toSet());\n    systemKeys.addAll(ADDITIONAL_SYSTEM_KEYS);\n\n    fileProperties.stringPropertyNames().stream()\n      .filter(key -> !systemKeys.contains(key))\n      .filter(key -> !key.startsWith(\"sonar.log.level.\"))\n      .filter(key -> MULTI_SERVER_LDAP_SETTINGS.stream().noneMatch(pattern -> key.matches(pattern.replace(\".\", \"\\\\.\").replace(\"*\", \"[^.]+\"))))\n      .sorted()\n      .forEach(key -> LOG.warn(\n        \"Property '{}' is not a recognized system property. It cannot be managed from the UI or API when set here, and it may have no effect. Please check the documentation.\",\n        key));\n  }","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java#L127-L163","documentation":"AppSettingsLoaderImpl.detectHomeDir locates the SonarQube installation by resolving the code source of the org.sonar.application.App class and walking up two directory levels to find the home directory. If the class cannot be loaded or its location is not a valid URI, an IllegalStateException 'Cannot detect path of main jar file' is thrown during loader construction.","triggerScenarios":"Constructing AppSettingsLoaderImpl when org.sonar.application.App is missing from the classpath (ClassNotFoundException) or its code source location cannot be converted to a URI (URISyntaxException, e.g. paths with illegal characters or running from an unpacked/exotic classloader setup).","commonSituations":"Running the server with a repackaged or trimmed jar, launching via custom classloaders/frameworks instead of the official start scripts, jar paths with special characters (spaces are usually fine but URL-encoded quirks can break toURI), or partially extracted distributions.","solutions":["Start SonarQube with the official scripts (bin/run.sh / StartSonar.bat) so the application jar is on the classpath as distributed","Verify sonar-application.jar exists in the lib directory and is not corrupted (reinstall/extract the distribution again)","Avoid custom classloaders or shading that renames/moves org.sonar.application.App","Move the installation to a plain path without unusual characters if URISyntaxException is the cause"],"exampleFix":"// before (custom launcher)\njava -cp my-custom-boot.jar org.sonar.server.Server  // App class absent\n// after\ncd sonarqube-<version>/bin/linux-x86-64 && ./sonar.sh start","handlingStrategy":"try-catch","validationCode":"try {\n  Class.forName(\"org.sonar.application.App\");\n} catch (ClassNotFoundException e) {\n  throw new IllegalStateException(\"sonar-application jar missing from classpath\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  settingsLoader = new AppSettingsLoaderImpl(...);\n} catch (IllegalStateException e) {\n  if (e.getMessage().equals(\"Cannot detect path of main jar file\")) {\n    log.error(\"Launch SonarQube with the official start scripts; check sonar-application.jar in lib/\", e.getCause());\n  }\n  throw e;\n}","preventionTips":["Always start via the distributed bin scripts, not custom classloaders","Verify sonar-application.jar exists in the lib directory after upgrades","Re-extract the distribution if jars are missing or corrupted","Install SonarQube at a plain filesystem path without exotic characters"],"tags":["java","classpath","startup"],"backgroundTag":"class-not-found","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}