【问题标题】:I entered mvn command in windows, but the command line return a java hint我在windows中输入了mvn命令,但是命令行返回一个java提示
【发布时间】:2015-06-01 12:14:21
【问题描述】:

我的机器 windows 8.1 上安装了 maven 3.3.1 和 java 1.7。

MAVEN_HOME=C:\Program Files\Apache\apache-maven-3.3.1
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_75
Path=%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;%MAVEN_HOME%\bin;

我尝试在 C:\Users\{myusername}> 下访问 mvn 命令行,效果很好:

C:\Users\{myusername}>java -version
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

C:\Users\{myusername}>mvn -version
Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T13:10:2
7-07:00)
Maven home: C:\Program Files\Apache\apache-maven-3.3.1\bin\..
Java version: 1.7.0_75, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_75\jre
Default locale: en_US, platform encoding: GBK
OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "windows"

但是当我将命令路径更改为 D:,我机器中的另一个磁盘时,输出变为:

D:\>mvn --version
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32          use a 32-bit data model if available
    -d64          use a 64-bit data model if available
    -server       to select the "server" VM
    -hotspot      is a synonym for the "server" VM  [deprecated]
                  The default VM is server.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A ; separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose:[class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument

    -splash:<imagepath>
                  show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for m
ore details.

D:\>java -version
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

另外,当我使用 Intellij 创建 maven 项目时,就像 quickstart 一样,发生了类似的错误:

-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.[ERROR] Maven execution terminated abnormally (exit code 1)

我尝试过 mvn -version、mvn -d。但它们仍然不起作用。 有人可以帮忙吗?谢谢!!

更新: 现在我的环境变量设置为:

JAVA_HOME=C:\Program Files\Java\jdk1.7.0_75;
CLASSPATH=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;
M2_HOME=C:\Program Files\Apache\apache-maven-3.3.1;
MAVEN_HOME=C:\Program Files\Apache\apache-maven-3.3.1;
PATH=%JAVA_HOME%\bin;%M2_HOME%\bin;{others...}

问题依然存在。

更新:

每当我在 D: 路径中键入 mvn 命令后,命令行只会返回 java 提示;似乎 mvn 之后的所有内容都被忽略了。 就像这样:

D:\>mvn fewadsfe
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32          use a 32-bit data model if available
    -d64          use a 64-bit data model if available
    -server       to select the "server" VM
    -hotspot      is a synonym for the "server" VM  [deprecated]
                  The default VM is server.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A ; separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose:[class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument

    -splash:<imagepath>
                  show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for m
ore details.

【问题讨论】:

  • 你是如何设置环境变量的?另外,不要把jre放在文件夹Path=%JAVA_HOME%\bin;%MAVEN_HOME%\bin;
  • 是的,我已经删除了 Path 环境变量的 jre 文件夹。但是问题依然存在……
  • 只有两件事。 JAVA_HOME 必须正确设置,这意味着对于 Maven,它必须指向 JDK。只有 apache-maven-3.3.1/bin 的 bin 文件夹必须在您的路径中。这都是真正需要的。之后你应该运行mvn --version。更改环境变量后,您必须关闭并重新打开控制台。

标签: java maven


【解决方案1】:

我在使用 Apache Maven 3.6.0 的 Windows Server 2012 R2 中遇到了同样的问题。这是一个奇怪的问题。

我不得不删除 C:\.mvn 文件夹,它成功了!

【讨论】:

    【解决方案2】:

    如之前的回复所述,问题出在"-Dmaven.multiModuleProjectDirectory=C:\" 属性上。如果删除此属性周围的引号,则 java 命令可以正常工作。由于前面的反斜杠,结束引号似乎被视为路径的一部分。

    在mvn.cmd 之后添加以下行 :endDetectBaseDir 标记为我修复了它。我正在使用 maven 3.3.3。

    IF "%MAVEN_PROJECTBASEDIR:~-1%"=="\" set MAVEN_PROJECTBASEDIR=%MAVEN_PROJECTBASEDIR%\

    【讨论】:

      【解决方案3】:

      maven 3.3.1 和 windows 7 也有这个问题,我在论坛中找到了这个answer。在这个版本的 Maven 中,在驱动器的根目录(c:\、d:\、...)中发出命令行存在问题。在任何其他目录上发出命令都可以。

      【讨论】:

      • 这也是我的问题,我只是运行 mvn -version 来验证路径是否正确。当我看到这个时正要降级......谢谢
      • 是的,我认为这真的很有帮助!谢谢!
      【解决方案4】:

      我在使用 Maven 3.3.1 时遇到了同样的问题,但是当我尝试 3.2.5 版时,问题得到了解决。我不知道 windows 7/8 和 maven 3.3.1 有什么问题。

      【讨论】:

      • 是的。我想我已经用 Maven 更改了版本。谢谢!
      • 这里也一样。这个版本是 maven 在窗口 8 上的问题吗?
      【解决方案5】:

      在另一个驱动器上,您使用-- 而不是- 运行命令,这无法识别并打印-help。确保您正在使用

      mvn -version
      

      -Dmaven.multiModuleProjectDirectory 系统属性未设置。

      这是一个已知错误(更多详细信息here),现已修复。按照错误跟踪器中的说明更新或修补您当前的安装。

      在 IDEA 14.0.x 和 14.1 分支中修复,该修复将在 分别是 14.0.5 和 14.1.1。

      如果您想立即尝试修复,请执行以下操作:

      对于IDEA 14.0.3:

      1. 使用来自IDEA-137783-patch-for_IDEA_14.0.3.zip的补丁解压压缩包
      2. 备份并替换以下 jars

        • \plugins\maven\lib\maven.jar
        • \plugins\maven\lib\maven-server-api.jar

        使用存档中的罐子

      对于IDEA 14.1:

      1. 使用来自IDEA-137783-patch-for_IDEA_14.1.zip 的补丁解压缩存档
      2. 备份并替换以下 jars

        • \plugins\maven\lib\maven.jar
        • \plugins\maven\lib\maven-server-api.jar
        • \plugins\maven\lib\maven32-server-impl.jar

        使用存档中的罐子

      【讨论】:

      • 实际上我在两个磁盘上都尝试过“-”或“--”。但问题依然存在。
      • - 在D 驱动器上的输出是什么?
      • @NagArvindGudiseva 我刚刚收到通知,您的编辑未通过审核队列。如果您愿意,可以使用此 cmets 部分再次分享您的反馈。
      猜你喜欢
      • 2013-01-22
      • 2017-06-20
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-31
      • 1970-01-01
      相关资源
      最近更新 更多