{"record":{"id":"00a9617c1a3966f4","repo":"microsoft/aspire","slug":"java-application-resourcename-cannot-be-published-because-00a961","errorCode":null,"errorMessage":"Java application '{resourceName}' cannot be published because {description} '{authored}' contains whitespace, which a Dockerfile COPY instruction cannot express. Move it to a path without spaces.","messagePattern":"Java application '(.+?)' cannot be published because (.+?) '(.+?)' contains whitespace, which a Dockerfile COPY instruction cannot express\\. Move it to a path without spaces\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Java/JavaDockerfileGenerator.cs","lineNumber":441,"sourceCode":"        // Container paths are POSIX even when the AppHost authored a Windows-style relative path.\n        var normalized = authored.Replace('\\\\', '/');\n\n        if (normalized.StartsWith(\"./\", StringComparison.Ordinal))\n        {\n            normalized = normalized[2..];\n        }\n\n        if (IsPathRootedOnAnyPlatform(authored) || normalized.Split('/').Contains(\"..\"))\n        {\n            throw new DistributedApplicationException(\n                $\"Java application '{resourceName}' cannot be published because {description} '{authored}' \" +\n                $\"is outside the build context '{appDirectory}'. Only files under the application \" +\n                \"directory are uploaded to the container build.\");\n        }\n\n        if (normalized.Any(char.IsWhiteSpace))\n        {\n            throw new DistributedApplicationException(\n                $\"Java application '{resourceName}' cannot be published because {description} '{authored}' \" +\n                \"contains whitespace, which a Dockerfile COPY instruction cannot express. Move it to a \" +\n                \"path without spaces.\");\n        }\n\n        return normalized;\n    }\n\n    private static JavaBuildTool? DetectBuildToolForPublish(JavaAppResource resource, string appDirectory)\n        => JavaBuildToolResolver.Detect(\n            appDirectory,\n            resource.Name,\n            static message => new DistributedApplicationException(message));\n\n    /// <summary>\n    /// The JDK the build stage runs on, which is not necessarily the JDK the application targets.\n    /// </summary>\n    /// <remarks>","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Java/JavaDockerfileGenerator.cs#L423-L459","documentation":"After path-escape checks, NormalizeContextRelativePath rejects any path containing whitespace because the Dockerfile generator emits shell-form COPY instructions whose arguments are separated by spaces with no quoting support. A path like \"target/my app.jar\" cannot be expressed in the generated Dockerfile, so it throws DistributedApplicationException.","triggerScenarios":"Publishing a Java resource whose prebuilt jar path (via TryGetPrebuiltJarPath/selectArtifact) contains spaces, e.g. \"target/My App.jar\" or a project directory named \"Java App\".","commonSituations":"Project or output directories named with spaces (common on Windows desktops); jar names containing version strings with spaces.","solutions":["Rename the file or directory to remove spaces (e.g. \"MyApp.jar\", \"java-app/\").","Adjust your Maven/Gradle build finalName so the produced jar has no spaces.","Copy the artifact to a space-free relative path within the app directory and reference that."],"exampleFix":"// before\n.WithJarArtifact(\"target/My App.jar\")\n// after\n.WithJarArtifact(\"target/MyApp.jar\"); // or set <finalName>MyApp</finalName> in pom.xml","handlingStrategy":"validation","validationCode":"if (path.Any(char.IsWhiteSpace))\n    throw new ArgumentException($\"{path} contains whitespace, which Dockerfile COPY cannot express; rename it without spaces\");","typeGuard":null,"tryCatchPattern":"try { await PublishAsync(...); } catch (DistributedApplicationException ex) when (ex.Message.Contains(\"whitespace\")) { Console.Error.WriteLine(ex.Message); return 1; }","preventionTips":["Name projects, output directories, and jars without spaces (set Maven finalName / Gradle archiveBaseName).","Check jar file names produced by CI for spaces from version strings.","Audit resource paths for whitespace before publishing."],"tags":["java","docker","path-validation","whitespace"],"backgroundTag":"invalid-argument-format","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"}