Java 检查 Maven 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24221361/
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-08-14 10:52:54  来源:igfitidea点击:

Checking Maven Version

javaeclipsemaventomcatjar

提问by Chala

I have just installed maven. I downloaded distributive, extracted files and set bin value environment variables, but when I type mvn -versionin CMD I am getting message:

我刚刚安装了maven。我下载了分布式的、提取的文件并设置了 bin 值环境变量,但是当我输入mvn -versionCMD 时,我收到消息:

'mvn' is not recognized as an internal or external command,
operable program or batch file.

'mvn' 不是内部或外部命令,也不是
可运行的程序或批处理文件。

I am writing project. I have one project DatabaseAPI where I have logic of database and POJO classes. second project is CoreAPI where I have some methods. For DatabaseAPI I make a jar file using eclipse (export -> jar). In core I add external jar (DatabaseAPI.jar). For CoreAPI I make a jar file using eclipse (export -> jar). In core I add external jar (CoreAPI.jar) and I tried to start tomcat (I have servlets in my project and swing too). I got error during starting and error is ClassNotFoundException(One of the classes in CoreAPI did not find). Is it problem of exporting using Eclipse ?

我正在写项目。我有一个项目 DatabaseAPI,其中有数据库和 POJO 类的逻辑。第二个项目是 CoreAPI,我有一些方法。对于 DatabaseAPI,我使用 eclipse(导出 -> jar)制作了一个 jar 文件。在核心中,我添加了外部 jar (DatabaseAPI.jar)。对于 CoreAPI,我使用 eclipse(导出 -> jar)制作了一个 jar 文件。在核心中,我添加了外部 jar (CoreAPI.jar) 并尝试启动 tomcat(我的项目中有 servlet,也有 Swing)。我在启动过程中出错,错误是ClassNotFoundException(CoreAPI 中的一个类没有找到)。使用 Eclipse 导出有问题吗?

回答by Niemand

Type the command mvn -versiondirectly in your maven directory, you probably haven't added it to your PATH. Here areexplained details of how to add maven to your PATH variable (I guess you use Windows because you are talking about CMD).

mvn -version直接在您的 maven 目录中键入命令,您可能还没有将它添加到您的 PATH 中。这里解释了如何将 maven 添加到您的 PATH 变量的详细信息(我猜您使用的是 Windows,因为您在谈论 CMD)。

回答by Aleksandr Podkutin

You need to add path to svn.exefile to system environment, variable PATH, after that you can run command mvnfrom any folder. You can do it from command line(cmd.exe) like this, for example:

您需要将svn.exe文件的路径添加到系统环境变量PATH,之后您可以从任何文件夹运行命令mvn。您可以像这样从命令行(cmd.exe)执行此操作,例如:

set PATH=%PATH%;C:\maven\bin

Or you can got to the folder where mvn.exeis, and run your command there.

或者你可以进入mvn.exe所在的文件夹,然后在那里运行你的命令。

And you need not mvn -version, but mvn --versionparameter.

而你不需要mvn -version,而是mvn --version参数。

回答by Sajal Fouzdar

Open command prompt go inside the maven folder and execute mvn -version, it will show you maven vesrion al

打开命令提示符进入 maven 文件夹并执行 mvn -version,它会显示 maven vesrion al

回答by ROMANIA_engineer

Shorter

较短

mvn -v

or

或者

mvn --version

Output:

输出:

Apache Maven 3.0.5 (...)
Maven home: ...
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: ...
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
Apache Maven 3.0.5 (...)
Maven home: ...
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: ...
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"

The other command (mvn -version) works because it starts with mvn -v.
You can also try mvn -v123and you'll get the same output.

另一个命令 ( mvn -version) 有效,因为它以mvn -v.
您也可以尝试mvn -v123,您将获得相同的输出。

Details:

详情

mvn -h

or

或者

mvn --help

Output:

输出:

...
-V,--show-version                      Display version information
                                       WITHOUT stopping build
-v,--version                           Display version information
...
-V,--show-version                      Display version information
                                       WITHOUT stopping build
-v,--version                           Display version information

Command is not recognized

无法识别命令

Probably you are in one of the following 2 situations:

您可能处于以下两种情况之一:

  1. You didn't add the Maven to the Path
    (run ECHO.%PATH:;= & ECHO.%in cmd to see if you are in this situation).
    • go to Control Panel\User Accounts\User Accounts
      (or click on your photo from the start menu)
    • click Change my environment variables
    • click on New...and add:
      • M2_HOME=<your_path>
      • MAVEN_HOME=%M2_HOME%
      • MAVEN_BIN=%M2_HOME%\bin
    • click on Edit...and add the ;%MAVEN_BIN%at the end of the Path
  2. You added it to the Path, but you didn't open a new command prompt.
    • open a new command prompt, because the environment variables are not updated automatically
  1. 您没有将 Maven 添加到Path
    ECHO.%PATH:;= & ECHO.%在 cmd 中运行以查看您是否处于这种情况)。
    • 转到控制面板\用户帐户\用户帐户
      (或从开始菜单中单击您的照片)
    • 单击更改我的环境变量
    • 单击新建...并添加:
      • M2_HOME=<your_path>
      • MAVEN_HOME=%M2_HOME%
      • MAVEN_BIN=%M2_HOME%\bin
    • 单击编辑...;%MAVEN_BIN%在末尾添加Path
  2. 您将它添加到Path,但没有打开新的命令提示符。
    • 打开一个新的命令提示符,因为环境变量不会自动更新

回答by KaviK

Step 1: Start button -> Computer menu item -> Properties on right click menu item ->?Advanced System Settings button on left panel -> Advanced tab in System Properties dialog ->?Environment Variables button -> System variables table

步骤 1:开始按钮 -> 计算机菜单项 -> 右键菜单项中的属性 -> 左侧面板上的?高级系统设置按钮 -> 系统属性对话框中的高级选项卡 ->?环境变量按钮 -> 系统变量表

Step 2: Add?MAVEN_HOME?variable

第 2 步:添加?MAVEN_HOME?变量

enter image description here

在此处输入图片说明

Step 3: Update?PATH?variable enter image description here

第 3 步:更新?PATH?变量 在此处输入图片说明

Step 4: Make sure you have?JAVA_HOME?variable correctly enter image description here

第 4 步:确保你有 ?JAVA_HOME? 变量正确 在此处输入图片说明

step 5: open console and check below command

第 5 步:打开控制台并检查以下命令

mvn -v

mvn -v

回答by rasoul poordelan

you can use just

你可以只用

     <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version></version>
    </dependency>

回答by bhuvana

i faced with similar issue when i first installed it. It worked when i added user variable name- PATH and variable value- C:\Program Files\apache-maven-3.5.3\bin

我第一次安装时遇到了类似的问题。当我添加用户变量名称 - PATH 和变量值 - C:\Program Files\apache-maven-3.5.3\bin 时,它起作用了

variable value should direct to "bin" folder. finally check with cmd (mvn -v) in a new cmd prompt. Good Luck :)

变量值应指向“bin”文件夹。最后在新的 cmd 提示中使用 cmd (mvn -v) 检查。祝你好运 :)

回答by Maureen Josephine

On terminal type mvn -vand the output will look like the image shown below

在终端类型上mvn -v,输出将如下图所示

enter image description here

在此处输入图片说明