{"record":{"id":"434909f480557efa","repo":"microsoft/aspire","slug":"java-application-resource-name-cannot-be-published-because-434909","errorCode":null,"errorMessage":"Java application '{resource.Name}' cannot be published because the OpenTelemetry agent path '{authored}' is a Windows path, which cannot resolve inside the Linux image the application is published to. Use a path inside the application directory so it is copied into the image, or an absolute path the base image or a mount provides at runtime.","messagePattern":"Java application '(.+?)' cannot be published because the OpenTelemetry agent path '(.+?)' is a Windows path, which cannot resolve inside the Linux image the application is published to\\. Use a path inside the application directory so it is copied into the image, or an absolute path the base image or a mount provides at runtime\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Java/JavaDockerfileGenerator.cs","lineNumber":574,"sourceCode":"\n        if (!resource.TryGetLastAnnotation<JavaOtelAgentAnnotation>(out var annotation))\n        {\n            return false;\n        }\n\n        var authored = JavaHostingExtensions.ResolveOtelAgentPath(resource, annotation);\n\n        if (IsPathRootedOnAnyPlatform(authored))\n        {\n            // A POSIX absolute path is a legitimate arrangement: the base image or a mount provides the\n            // agent, and rewriting it would break that. A Windows-rooted path cannot be, because the\n            // image the AppHost publishes to is Linux. Leaving it alone puts \"-javaagent:C:\\...\" into\n            // JAVA_TOOL_OPTIONS, and the JVM then dies during VM initialization with an error that\n            // names the agent but not the reason. The jar artifact and the wrapper already reject\n            // Windows-rooted paths on every platform; this keeps the agent consistent with them.\n            if (IsWindowsRooted(authored))\n            {\n                throw new DistributedApplicationException(\n                    $\"Java application '{resource.Name}' cannot be published because the OpenTelemetry agent \" +\n                    $\"path '{authored}' is a Windows path, which cannot resolve inside the Linux image the \" +\n                    \"application is published to. Use a path inside the application directory so it is copied \" +\n                    \"into the image, or an absolute path the base image or a mount provides at runtime.\");\n            }\n\n            return false;\n        }\n\n        // Container paths are POSIX even when the AppHost authored a Windows-style relative path.\n        var normalized = authored.Replace('\\\\', '/');\n\n        // Strip a single leading \"./\" only. Trimming the '.' and '/' characters as a set would turn\n        // \"../agents/otel.jar\" into \"agents/otel.jar\" and emit a COPY for a path that was never in the\n        // build context, failing the container build with a path the author never wrote.\n        if (normalized.StartsWith(\"./\", StringComparison.Ordinal))\n        {\n            normalized = normalized[2..];","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Java/JavaDockerfileGenerator.cs#L556-L592","documentation":"TryGetBuildProducedAgentPath (used by Dockerfile generation and build-context ignore computation) rejects a Windows-rooted OpenTelemetry agent path. The published image is Linux, so a path like \"C:\\otel\\javaagent.jar\" would leak into JAVA_TOOL_OPTIONS as -javaagent:C:\\... and crash the JVM at startup with an error that names the agent but not the cause. Throwing at publish time surfaces the problem early; the jar and wrapper checks already reject Windows paths, and this keeps the agent consistent.","triggerScenarios":"Calling WithOtelAgent with a Windows-rooted path (drive letter or backslash-rooted, e.g. \"C:\\agents\\javaagent.jar\") on any platform, then publishing (Write or BuildContextIgnoreContent).","commonSituations":"Developing on Windows and authoring an absolute local path for the agent jar; paths auto-composed from Windows-specific environment variables or user-profile directories.","solutions":["Use a path relative to the application directory, e.g. WithOtelAgent(\"otel/javaagent.jar\"), so the jar is copied into the image.","Or use a Linux absolute path that the base image or a mount provides at runtime, e.g. \"/opt/otel/javaagent.jar\".","Remove drive letters and backslashes; normalize to forward slashes."],"exampleFix":"// before\n.WithOtelAgent(@\"C:\\tools\\otel\\javaagent.jar\")\n// after\n.WithOtelAgent(\"otel/javaagent.jar\");","handlingStrategy":"validation","validationCode":"if (System.Text.RegularExpressions.Regex.IsMatch(agentPath, @\"^[A-Za-z]:[\\\\/]|^\\\\\\\\\"))\n    throw new ArgumentException(\"Otel agent path must be a relative app-directory path or a Linux absolute path, not a Windows path\");","typeGuard":null,"tryCatchPattern":"try { await PublishAsync(...); } catch (DistributedApplicationException ex) when (ex.Message.Contains(\"OpenTelemetry agent\")) { Console.Error.WriteLine(ex.Message); return 1; }","preventionTips":["Never use Windows drive-letter or backslash-rooted paths in resource configuration, even on Windows dev machines.","Prefer relative paths under the app directory for the agent jar.","Use Linux-style absolute paths only when the base image or a mount actually provides the file."],"tags":["java","docker","opentelemetry","windows-path"],"backgroundTag":"unsupported-platform","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}