java Maven - “此时文件是意外的”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34631826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 23:08:05  来源:igfitidea点击:

Maven - "files was unexpected at this time"

javamaven

提问by kushan

I'm trying to install maven to my PC.(windows 7)

我正在尝试将 maven 安装到我的电脑上。(Windows 7)

Following are the steps I have done.

以下是我所做的步骤。

1. Installed Java 1.8.0.11
2. Added a system variable JAVA_HOME = C:\Program Files\Java\jdk1.8.0_11
3. Appended it to the path -  PATH=%JAVA_HOME%\bin;C:\Program Files\......;... etc
4. Typed "Java -version" in command line and got the java version details as usual.
5. Then I downloaded and extracted the Maven 3.3.3 
6. Added the M2_HOME to system variable.M2_HOME=C:\Program Files\apache-maven-3.3.3\apache-maven-3.3.3
7. Added M2 Variable  M2=%M2_HOME%\bin
8. Appended M2 to Path variable. PATH=%M2%;%JAVA_HOME%\bin;....;...etc
9. Typed mvn --version in command line.

Get the following error.

得到以下错误。

Files was unexpected at this time.

此时文件出乎意料。

What is wrong here? Please help me to get this resolved.

这里有什么问题?请帮我解决这个问题。

Thanks in advance!

提前致谢!

**Note - I have not use quotes for any of the paths here. also I tried with 8 char syntax for folder names like this:

**注意 - 我没有对这里的任何路径使用引号。我还尝试使用 8 个字符的语法作为文件夹名称,如下所示:

set java_home="c:\Progra~1\Java"

设置 java_home="c:\Progra~1\Java"

Non of these were resolved the issue. Please read the steps I have added and help me to get this resolved.**

这些都没有解决问题。请阅读我添加的步骤并帮助我解决这个问题。**

回答by kushan

Finally I was able to resolved the issue.

最后我能够解决这个问题。

A quoted value in the user variables has caused to the "Files were unexpected at this time" error in maven.

用户变量中的引用值导致了 maven 中的“此时文件意外”错误。

I spent hours of time with changing Java_home and M2_home variables with different combinations but finally checked the user variable and noted the quotes there.

我花了好几个小时用不同的组合更改 Java_home 和 M2_home 变量,但最终检查了用户变量并注意到了那里的引号。

Home = "C:\Program Files (x86)\Git\bin"

Removed the quotes and change the git home variable as below and now all works fine. :)

删除引号并更改 git home 变量如下,现在一切正常。:)

Home = C:\Program Files (x86)\Git\bin

This is where the error was

这是错误所在

回答by Andrei

I had a similar issue
Files\apache-maven-3.3.9""=="" was unexpected at this time.
and when looking at "Environment Variables" inside "System Properties" there were no quotes (") inside of any variables, but before doing that I was following a tutorial and set those values via cmd:
C:\Program Files\apache-maven-3.3.9\bin>set M2_HOME="C:\Program Files\apache-maven-3.3.9"
So, in order to fix it I just re-run the following in cmd:
C:\Program Files\apache-maven-3.3.9\bin>set M2_HOME=C:\Program Files\apache-maven-3.3.9
(removed " from cmd assignment) I hope this helps someone.

我有一个类似的问题
Files\apache-maven-3.3.9""=="" was unexpected at this time.
,当查看“系统属性”中的“环境变量”时,任何变量中都没有引号 ("),但在此之前,我正在学习教程并通过 cmd 设置这些值:
C:\Program Files\apache-maven-3.3.9\bin>set M2_HOME="C:\Program Files\apache-maven-3.3.9"
所以,为了要修复它,我只是在 cmd 中重新运行以下内容:(
C:\Program Files\apache-maven-3.3.9\bin>set M2_HOME=C:\Program Files\apache-maven-3.3.9
从 cmd 分配中删除了“)我希望这对某人有所 帮助。

回答by harshal bhavsar

I was facing same issue in jenkinswhen I asked jenkins to install maveninternally. Notice double quotes below when jenkinswas firing a build

jenkins当我要求 jenkins 在maven内部安装时,我遇到了同样的问题。在jenkins触发构建时注意下面的双引号

 '""C:\Program Files (x86)\Jenkins\tools\hudson.tasks.Maven_MavenInstallation\maven\bin\mvn.cmd"' -f ./Voyager/pom.xml clean package....

To resolve this I downloaded maven and manually set the path in jenkins and it was resolved.

为了解决这个问题,我下载了 maven 并在 jenkins 中手动设置了路径并解决了。

回答by NDP

Try adding

尝试添加

C:\Program Files\apache-maven-3.3.3\apache-maven-3.3.3\bin

to PATHvariable

PATH变量