[英]How can I run a program compiled by Maven?
I am starting to learn Maven by reading https://spring.io/guides/gs/maven/ . 我通过阅读https://spring.io/guides/gs/maven/开始学习Maven。
In the examples, after running mvn compile
successfully, how can I run the program via maven? 在示例中,成功运行
mvn compile
后,如何通过maven运行程序? This part seems missing from the article. 该部分似乎缺少本文。
Thanks. 谢谢。
You can invoke a Java program (ie with a public static void main(String[] args)
signature) with the classpath of the combined dependencies for the current pom.xml using 您可以使用当前pom.xml的组合依赖项的类路径调用Java程序(即,使用
public static void main(String[] args)
签名)。
mvn -q exec:java
You need to configure the main class to invoke in your pom.xml similar to 您需要配置主类以在pom.xml中调用,类似于
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>demo.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
This is useful for testing and development, but not deployment 这对于测试和开发很有用,但对部署没有帮助
See http://www.mojohaus.org/exec-maven-plugin/usage.html for full details. 有关完整的详细信息,请参见http://www.mojohaus.org/exec-maven-plugin/usage.html 。
Generally, maven is not used for running code. 通常,maven不用于运行代码。 This is a build tool that you can use for compiling, running unit or integration tests, deploying you your code locally and remotely, etc..
这是一个构建工具,可用于编译,运行单元或集成测试,在本地和远程部署代码等。
It is based around the idea of a build lifecycle where which is in its turn is defined by a list of build phases. 它基于构建生命周期的思想,而构建生命周期又由一系列构建阶段定义。 For example, the default lifecycle has the following phases:
例如,默认生命周期具有以下阶段:
For more information you can refer to this . 有关更多信息,您可以参考此 。
UPDATE : 更新 :
Having said that, it is possible as mentioned in Thorbjørn Ravn Andersen answer here. 话虽如此,有可能在ThorbjørnRavn Andersen的答复中提到。
The Maven build process has a number of lifecycles, or points in the process. Maven构建过程具有多个生命周期或过程中的各个点。
compile
is one of the build steps, but most likely running the following would resolve your issue: compile
是构建步骤之一,但是很可能运行以下命令可以解决您的问题:
mvn clean package
This would generate a JAR file, in the folder where you ran it. 这将在运行它的文件夹中生成一个JAR文件。 You can then try running this JAR file using
java
. 然后,您可以尝试使用
java
运行此JAR文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.