Reputation: 99576
I am starting to learn Maven by reading https://spring.io/guides/gs/maven/.
In the examples, after running mvn compile
successfully, how can I run the program via maven? This part seems missing from the article.
Thanks.
Upvotes: 3
Views: 4542
Reputation: 6910
Generally, maven is not used for running code. 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.
Upvotes: 1
Reputation: 75426
You can invoke a Java program (i.e. with a public static void main(String[] args)
signature) with the classpath of the combined dependencies for the current pom.xml using
mvn -q exec:java
You need to configure the main class to invoke in your pom.xml similar to
<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.
Upvotes: 2
Reputation: 522751
The Maven build process has a number of lifecycles, or points in the process. compile
is one of the build steps, but most likely running the following would resolve your issue:
mvn clean package
This would generate a JAR file, in the folder where you ran it. You can then try running this JAR file using java
.
Upvotes: 1