{"record":{"id":"6bd161571c31f07b","repo":"apache/skywalking","slug":"can-not-locate-oap-core-jar-file-by-url","errorCode":null,"errorMessage":"Can not locate oap core jar file by url:{}","messagePattern":"Can not locate oap core jar file by url:(.+?)","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":61,"sourceCode":"    private static File findPath() {\n        String classResourcePath = WorkPath.class.getName().replaceAll(\"\\\\.\", \"/\") + \".class\";\n\n        URL resource = ClassLoader.getSystemClassLoader().getResource(classResourcePath);\n        if (resource != null) {\n            String urlString = resource.toString();\n\n            LOGGER.debug(\"The beacon class location is {}.\", urlString);\n\n            int insidePathIndex = urlString.indexOf('!');\n            boolean isInJar = insidePathIndex > -1;\n\n            if (isInJar) {\n                urlString = urlString.substring(urlString.indexOf(\"file:\"), insidePathIndex);\n                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":43,"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#L43-L78","documentation":"UnexpectedException thrown while resolving the OAP server's working directory: WorkPath locates the server-core jar via its own class resource URL, and when the class is inside a jar (a '!' appears in the URL) it converts the 'file:...!...' prefix into a java.io.File. This variant is the MalformedURLException catch: new URL(urlString) rejected the trimmed URL string, meaning the URL does not start with a protocol WorkPath expected after substring surgery.","triggerScenarios":"Running OAP from a classpath layout where the class resource URL contains '!' but the 'file:' index/substring extraction produces a non-URL string (e.g. nested jars from Spring Boot thin launches, jshell/custom classloaders, or URLs like jar:file: read oddly). new URL(...) then throws MalformedURLException wrapped in UnexpectedException.","commonSituations":"Custom packaging/embedding OAP classes outside the official dist tarball; running with a shaded/uber jar or a launcher that produces unusual resource URLs; JDK changes in URL handling across versions.","solutions":["Run OAP from the official apache-skywalking dist layout (unpacked tarball/docker image) where server-core.jar sits as a plain file","If embedding, ensure org.apache.skywalking.oap.server.core.WorkPath is loaded from a normal file-system jar URL (file:/path/server-core.jar!/...)","Check for nested-jar classloading and switch to a classpath-based launch","As a diagnostic, print the resource URL for WorkPath.class before it fails to see the malformed prefix"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"URL u = WorkPath.class.getClassLoader().getResource(\"org/apache/skywalking/oap/server/core/WorkPath.class\");\nboolean jarShape = u != null && u.toString().contains(\"!\") && u.toString().startsWith(\"file:\");\nif (!jarShape) {\n    LOGGER.warn(\"Non-standard classpath layout: {}\", u);\n}","typeGuard":null,"tryCatchPattern":"try {\n    File workPath = WorkPath.getAndSet(); // or equivalent lookup\n} catch (UnexpectedException e) {\n    throw new IllegalStateException(\"OAP must run from the standard dist layout; classpath URL was not a file-jar: \" + e.getMessage(), e);\n}","preventionTips":["Deploy OAP from the official tarball or Docker image; do not shade/relocate server-core into an uber-jar","Log the WorkPath.class resource URL in wrapper scripts when debugging unusual launches","Test the exact production launcher (systemd unit, container entrypoint) in staging, not just IDE runs"],"tags":["classpath","packaging","startup","jar","oap-server"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}