{"record":{"id":"72b6eeccef97088c","repo":"apache/skywalking","slug":"can-not-locate-oap-core-jar-file-by-path","errorCode":null,"errorMessage":"Can not locate oap core jar file by path:{}","messagePattern":"Can not locate oap core jar file by path:(.+?)","errorType":"exception","errorClass":"UnexpectedException","httpStatus":null,"severity":"error","filePath":"oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/WorkPath.java","lineNumber":75,"sourceCode":"                File agentJarFile = null;\n                try {\n                    agentJarFile = new File(new URL(urlString).toURI());\n                } catch (MalformedURLException e) {\n                    throw new UnexpectedException(\"Can not locate oap core jar file by url:\" + urlString, e);\n                } catch (URISyntaxException e) {\n                    throw new UnexpectedException(\"Can not locate oap core jar file by url:\" + urlString, e);\n                }\n                if (agentJarFile.exists()) {\n                    return agentJarFile.getParentFile();\n                }\n            } else {\n                int prefixLength = \"file:\".length();\n                String classLocation = urlString.substring(prefixLength, urlString.length() - classResourcePath.length());\n                return new File(classLocation);\n            }\n        }\n\n        throw new UnexpectedException(\"Can not locate oap core jar file by path:\" + classResourcePath);\n    }\n}\n","sourceCodeStart":57,"sourceCodeEnd":78,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/WorkPath.java#L57-L78","documentation":"UnexpectedException thrown at the end of WorkPath's lookup: neither branch succeeded in turning the class resource path of org.apache.skywalking.oap.server.core.WorkPath into a directory — either the resource URL was null / not jar-shaped in a recognizable way, or the jar file derived from it did not exist on disk. The message echoes classResourcePath, the resource name used for ClassLoader.getResource(...).","triggerScenarios":"Loading WorkPath through a classloader whose getResource returns null (some embedded/OSGi setups) or returns a URL whose file: prefix does not map to an existing File (e.g. jrt:/ JPMS modules, remote/http classloaders, in-memory classloaders). The isInJar branch falls through when agentJarFile.exists() is false, reaching the final throw.","commonSituations":"Running OAP classes inside a custom container/IDE with a non-file classloader; JPMS jlink runtime; tests instantiating core classes with a classpath the path logic cannot map; bytecode-manipulation agents altering resource URLs.","solutions":["Run from the standard dist layout (oap-libs/*.jar as plain files) or the official Docker image","If running under JPMS/jlink, put server-core on the class path (not module path) so its URL is file:-based","In tests, avoid code paths that call WorkPath; or pre-set the working directory mechanism the code exposes instead of relying on classpath probing","Verify with a snippet that getClassLoader().getResource('org/apache/skywalking/oap/server/core/WorkPath.class') returns a file: URL before launching"],"exampleFix":"// diagnostic before launch\nClassLoader cl = WorkPath.class.getClassLoader();\nSystem.out.println(cl.getResource(\"org/apache/skywalking/oap/server/core/WorkPath.class\"));\n// must print a file:/...!/... URL; jrt:/ or null reproduces error 188","handlingStrategy":"try-catch","validationCode":"URL u = WorkPath.class.getClassLoader().getResource(\"org/apache/skywalking/oap/server/core/WorkPath.class\");\nif (u == null || !(\"file\".equals(u.getProtocol()) || \"jar\".equals(u.getProtocol()))) {\n    throw new IllegalStateException(\"Unsupported classloader for OAP core; resource URL: \" + u);\n}","typeGuard":null,"tryCatchPattern":"try {\n    File dir = WorkPath.lookup();\n} catch (UnexpectedException e) {\n    // fall back to an explicitly configured working directory if your wrapper supports it\n    LOGGER.error(\"Cannot derive work path from classpath ({}); use the standard dist layout\", e.getMessage());\n    throw e;\n}","preventionTips":["Run server-core on the class path, not the JPMS module path (jrt: URLs are unsupported)","Avoid embedding OAP in custom classloader trees (OSGi, isolated LEAs) without providing file-based resources","Add a boot-time diagnostic that prints the core class resource URL to catch layout issues before WorkPath runs"],"tags":["classpath","packaging","classloader","startup","oap-server"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}