How to write a Maven script assembly to execute Java

How can I execute a Java program at build time or after the build has just finished? Is it possible to do this directly from pom?

mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main

EDIT

Say I want to perform org.eclipse.content.MyClass. How did I need to write the code?

This creates the project, but it does not execute my class:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <phase>deploy</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>org.eclipse.content.MyClass</mainClass>
                </configuration>
            </plugin>
+3
source share
2 answers

Configure maven-exec-plugin using pom

<build>
<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
      <execution>
        <phase>yourPhase</phase>
        ...
        <goals>
          <goal>java</goal>
        </goals>
           <configuration>
             <mainClass>mainClass=org.sonatype.mavenbook.weather.Main</mainClass>
          </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
</build>

In the line, <phase>yourPhase</phase>insert the maven phase in what this plugin should run.

pom classpath ( ). , , , exec.

+4
+2

Source: https://habr.com/ru/post/1732328/


All Articles