Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven: execute without actually building anything

I have a project with finalised version in pom files , lets say 12.3.45 . I have built the code for this version some time ago already, all the built jars are in the local maven repo.

Then at some point I have run mvn clean, so all the target folders are being removed.

And now I want to execute some code, as quickly as possible, using mvn exec:java. Preferably without building anything, because why not? all the jars at some point were already built, and I know there were no code changes after that. How can I force maven to execute the code as fast as possible , not recompile anything, and just reuse the jars from the local repo? Thanks.

like image 896
javagirl Avatar asked Dec 03 '25 16:12

javagirl


1 Answers

  • If your artifacts are in a local or remote repository you can use them as dependencies.
  • You can use exec-maven-plugin's options includeProjectDependencies or includePluginDependencies to use them in java execution https://www.mojohaus.org/exec-maven-plugin/java-mojo.html#includePluginDependencies. includeProjectDependencies option is enabled (true) by default.
  • You can execute exec-maven-plugin without building anything with mvn exec:java command

Instructions:

To run exec-maven-plugin you would need a main class to run. I assume you have one in your project. If you don't - you need to make a separate project with a main class.

  1. Create a blank maven project.
  2. In the project add exec-maven-plugin configuration. Set the mainClass
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>pack.App</mainClass>
                </configuration>
        </plugin>
    </plugins>
</build>
  1. Include you artifacts as dependencies to the project
<dependencies>
    <dependency>
        <groupId>my.group</groupId>
        <artifactId>myartifact</artifactId>
        <version>12.3.45</version>
    </dependency>
</dependencies>
  1. Run mvn exec:java to execute com.my.package.MyMainClass main class from my.group.myartifact artifact

Edits:

  • includeProjectDependencies option is enabled (true) by default
like image 157
Vitaly Roslov Avatar answered Dec 06 '25 05:12

Vitaly Roslov