{"record":{"id":"802c321548b65834","repo":"SonarSource/sonarqube","slug":"cannot-load-s-from-classpath","errorCode":null,"errorMessage":"Cannot load %s from classpath","messagePattern":"Cannot load (.+?) from classpath","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-main/src/main/java/org/sonar/application/config/SonarQubeVersionHelper.java","lineNumber":55,"sourceCode":"\n  public static String getSonarqubeVersion() {\n    if (sonarqubeVersion == null) {\n      loadVersion();\n    }\n    return sonarqubeVersion;\n  }\n\n  private static synchronized void loadVersion() {\n    try {\n      try (BufferedReader in = new BufferedReader(\n        new InputStreamReader(\n          SonarQubeVersionHelper.class.getResourceAsStream(SONARQUBE_VERSION_PATH),\n          StandardCharsets.UTF_8\n        ))) {\n        sonarqubeVersion = in.readLine();\n      }\n    } catch (IOException e) {\n      throw new IllegalStateException(format(\"Cannot load %s from classpath\", SONARQUBE_VERSION_PATH), e);\n    }\n  }\n}\n","sourceCodeStart":37,"sourceCodeEnd":59,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-main/src/main/java/org/sonar/application/config/SonarQubeVersionHelper.java#L37-L59","documentation":"SonarQubeVersionHelper reads the embedded sonar-api-version (SONARQUBE_VERSION_PATH) resource from the classpath to determine the running SonarQube version. If the resource stream cannot be read and an IOException occurs, it wraps it in an IllegalStateException 'Cannot load <path> from classpath'. It indicates the packaged version file is missing or unreadable.","triggerScenarios":"IOException while reading SONARQUBE_VERSION_PATH from the classpath — e.g. the resource stream was null/unreadable, a broken JAR packaging stripped the resource, or an IO error opening the stream inside the try-with-resources.","commonSituations":"Custom or trimmed distributions that excluded the version resource file; corrupted installation JARs; shading/assembly plugins that fail to copy resources into the artifact; running from a partially extracted distribution.","solutions":["Re-download/reinstall the unmodified SonarQube distribution","Verify the version resource file exists inside the JAR (e.g. unzip -l sonar-application.jar | grep version)","Check assembly/shade resource includes if building SonarQube from source","Inspect the wrapped IOException cause for the underlying filesystem problem"],"exampleFix":"// pom.xml resource filtering excluding files\n<resources><resource><directory>src/main/resources</directory><excludes><exclude>**/sonar-api-version.txt</exclude></excludes></resource></resources>\n// after: remove the exclude so the version file ships in the JAR","handlingStrategy":"try-catch","validationCode":"try (InputStream in = SonarQubeVersionHelper.class.getResourceAsStream(\"/sonar-api-version.txt\")) {\n  if (in == null) throw new IllegalStateException(\"Version resource missing from distribution JAR\");\n}","typeGuard":null,"tryCatchPattern":"try { Version v = SonarQubeVersionHelper.getSonarqubeVersion(); } catch (IllegalStateException e) { log.error(\"Version resource unreadable; reinstall distribution\", e); throw e; }","preventionTips":["Use official, unmodified SonarQube distributions","If repackaging, ensure resource files are included in assembly/shade config","Verify JAR integrity after downloads","Inspect the IOException cause for classpath/IO issues"],"tags":["classpath","resources","version","sonarqube"],"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-14T05:17:10.506Z"}