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
How I run maven project in cmd line
提问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
- cd to your project root folder in command line.
- mvn compile
- mvn exec:java -Dexec.mainClass=com.kub.App
- 在命令行中 cd 到您的项目根文件夹。
- 编译
- mvn exec:java -Dexec.mainClass=com.kub.App
回答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
Please make sure that
JAVA_HOME
andMAVEN_HOME
path 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
Add both paths in environment variable 'Path' as follows:
%MAVEN_HOME%\bin
%JAVA_HOME%\bin
Open your project using IDE (in my case I am using intelliJIDEA)
- Click on Run button and copy the command executed in console window.
- Open cmd and traverse to the root folder of your maven project.
- Paste and execute the copied command and your project will run successfully.
请确保在环境变量中设置
JAVA_HOME
和MAVEN_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
在环境变量 'Path' 中添加两个路径,如下所示:
%MAVEN_HOME%\bin
%JAVA_HOME%\bin
使用 IDE 打开您的项目(在我的情况下,我使用的是 intelliJIDEA)
- 单击运行按钮并复制在控制台窗口中执行的命令。
- 打开cmd,遍历到你的maven项目的根文件夹。
- 粘贴并执行复制的命令,您的项目将成功运行。
回答by question_maven_com
Go to project :
转到项目:
- open cmd
cd c:/project
mvn clean install
java -jar -Dapple.awt.UIElement="true" target/myproject-1.0-SNAPSHOT.jar -h
- 打开cmd
cd c:/project
mvn clean install
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