eclipse 我如何在 cmd 行中运行 maven 项目

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

How I run maven project in cmd line

eclipsemavenjarcmd

提问by kbry

I write maven project and I run it in Eclipse but I want to run maven project in using command line so I write

我编写了 Maven 项目并在 Eclipse 中运行它,但我想使用命令行运行 Maven 项目,所以我写

java -jar -Dapple.awt.UIElement="true" target/myproject-1.0-SNAPSHOT.jar -h

line in cmd but I have this error http://i.stack.imgur.com/c03mN.png.

在 cmd 行,但我有这个错误http://i.stack.imgur.com/c03mN.png

How can I solve it?

我该如何解决?

回答by Thu Rein Tin

  1. cd to your project root folder in command line.
  2. mvn compile
  3. mvn exec:java -Dexec.mainClass=com.kub.App
  1. 在命令行中 cd 到您的项目根文件夹。
  2. 编译
  3. mvn exec:java -Dexec.mainClass=com.kub.App

Please check for more informations here.

请在此处查看更多信息。

回答by Priyansh Sheth

You can run mavan spring-boot project using the following command

您可以使用以下命令运行 mavan spring-boot 项目

mvn spring-boot:run

mvn spring-boot:run

回答by Amit Joshi

  1. Please make sure that JAVA_HOMEand MAVEN_HOMEpath are set in environment variables as follows:

    JAVA_HOME: C:\Program Files\Java\jdk1.8.0_181(Path till JDK folder only not bin folder) MAVEN_HOME: C:\Users\Amit Joshi\Downloads\apache-maven-3.6.0

  2. Add both paths in environment variable 'Path' as follows: %MAVEN_HOME%\bin%JAVA_HOME%\bin

  3. Open your project using IDE (in my case I am using intelliJIDEA)

  4. Click on Run button and copy the command executed in console window.
  5. Open cmd and traverse to the root folder of your maven project.
  6. Paste and execute the copied command and your project will run successfully.
  1. 请确保在环境变量中设置JAVA_HOMEMAVEN_HOME路径如下:

    JAVA_HOME: C:\Program Files\Java\jdk1.8.0_181(JDK 文件夹的路径,不是 bin 文件夹) MAVEN_HOME:C:\Users\Amit Joshi\Downloads\apache-maven-3.6.0

  2. 在环境变量 'Path' 中添加两个路径,如下所示: %MAVEN_HOME%\bin%JAVA_HOME%\bin

  3. 使用 IDE 打开您的项目(在我的情况下,我使用的是 intelliJIDEA)

  4. 单击运行按钮并复制在控制台窗口中执行的命令。
  5. 打开cmd,遍历到你的maven项目的根文件夹。
  6. 粘贴并执行复制的命令,您的项目将成功运行。

回答by question_maven_com

Go to project :

转到项目:

  1. open cmd
  2. cd c:/project
  3. mvn clean install
  4. java -jar -Dapple.awt.UIElement="true" target/myproject-1.0-SNAPSHOT.jar -h
  1. 打开cmd
  2. cd c:/project
  3. mvn clean install
  4. java -jar -Dapple.awt.UIElement="true" target/myproject-1.0-SNAPSHOT.jar -h

Add this in pom:

在 pom 中添加:

    <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>com.kub.App</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
     </plugins>

回答by johnstreip

Are you sure that you are in the correct path for loading the .jar file?

您确定您在加载 .jar 文件的正确路径中吗?

maybe you need something like this?

也许你需要这样的东西?

java -jar -Dapple.awt.UIElement="true" USERS/eclipse-project/projectname/target/myproject-1.0-SNAPSHOT.jar -h