用于演示 spring-boot 项目的 mvnw.cmd 无法在 Windows 中工作

Sac*_*hin 5 spring-boot spring-initializr maven-wrapper

2.3.0从 Spring Initializr 到我的 Windows8.1操作系统生成了一个简单的演示项目(版本),下面是基本结构

\n\n
C:.\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80src\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80main\n    \xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80java\n    \xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80com\n    \xe2\x94\x82   \xe2\x94\x82       \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80example\n    \xe2\x94\x82   \xe2\x94\x82           \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80demo\n    \xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80resources\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80test\n        \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80java\n            \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80com\n                \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80example\n                    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80demo\n
Run Code Online (Sandbox Code Playgroud)\n\n

我尝试运行mvnw.cmd clean并收到以下错误:

\n\n
C:\\Users\\Downloads\\demo\\demo>mvnw.cmd clean\n"}" was unexpected at this time.\n
Run Code Online (Sandbox Code Playgroud)\n\n

下面是 powershell 中的相同输出

\n\n
PS C:\\Users\\Downloads\\demo\\demo> .\\mvnw.cmd clean\n"}" was unexpected at this time.\nPS C:\\Users\\Downloads\\demo\\demo>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我发现问题发生在mvnw.cmd文件中的以下几行中:

\n\n
powershell -Command "&{"^\n    "$webclient = new-object System.Net.WebClient;"^\n    "if (-not ([string]::IsNullOrEmpty(\'%MVNW_USERNAME%\') -and [string]::IsNullOrEmpty(\'%MVNW_PASSWORD%\'))) {"^\n    "$webclient.Credentials = new-object System.Net.NetworkCredential(\'%MVNW_USERNAME%\', \'%MVNW_PASSWORD%\');"^\n    "}"^\n    "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile(\'%DOWNLOAD_URL%\', \'%WRAPPER_JAR%\')"^\n    "}"\n
Run Code Online (Sandbox Code Playgroud)\n\n

不确定我是否遗漏了什么。

\n

Pow*_*015 0

我刚刚遇到了同样的问题,cmd 和 powershell 均出错。只需将项目复制到另一个目录即可解决问题。

我使用的是 Windows 10,该项目最初位于我的下载目录中。我把它移到了文档中。