Search code examples
maventaskpackaging

Maven - execute method before packaging


I have a Maven project with Spring Boot application.

There is some class with some method in application. This method create some new files in application folder using some complicated logic. After application is deployed it is using this files while running.

Presently I execute this method manualy rigth before packaging and deploying of application. I want to automatize this process - I want Maven execute this method before packaging.

Is it possible? How?


Solution

  • You can add an exec plugin

    <build>  
     <plugins>  
      <plugin>  
       <groupId>org.codehaus.mojo</groupId>  
       <artifactId>exec-maven-plugin</artifactId>  
       <version>1.1.1</version>  
       <executions>  
        <execution>  
         <phase>test</phase>  
         <goals>  
          <goal>java</goal>  
         </goals>  
         <configuration>  
          <mainClass>com.vineetmanohar.module.CodeGenerator</mainClass>  
          <arguments>  
           <argument>arg0</argument>  
           <argument>arg1</argument>  
          </arguments>  
         </configuration>  
        </execution>  
       </executions>  
      </plugin>  
     </plugins>  
    

    Good example here