Maven, run a java method or script before war is about to be built

╄→гoц情女王★ 提交于 2019-12-13 20:43:00

问题


I am thinking of using a template engine to generate the web.xml and other things.

Is there as way to to run a java file or a script before the maven install command? Or before the war is generated.

I am not sure what the phase should be, but basically before anyone else looks at the web.xml so I can touch it to make a new valid one.


回答1:


You can use the exec-maven-plugin to run either a program/script (using the exec goal) or a Java program (using the java goal).

The phase immediately before package is prepare-package (see the Default lifecycle in the Lifecycle Reference), so you could use that. But you might prefer to generate the web.xml earlier in the lifecycle (even as early as generate-resources).

Putting these together, you might try something like this:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.3.2</version>
    <executions>
      <execution>
        <phase>prepare-package</phase>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <executable>your_packaging_script</executable>
      <!-- optional -->
      <workingDirectory>/tmp</workingDirectory>
      <arguments>
        <argument>--some-option</argument>
      </arguments>
    </configuration>
  </plugin>

Alternatively, you might consider writing your own plugin, especially if you think the idea would be useful for more than one project.



来源:https://stackoverflow.com/questions/25352751/maven-run-a-java-method-or-script-before-war-is-about-to-be-built

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!