Maven,在战争即将建成之前运行java方法或脚本 [英] Maven, run a java method or script before war is about to be built

查看:294
本文介绍了Maven,在战争即将建成之前运行java方法或脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用模板引擎来生成web.xml和其他东西。



是否可以在 maven install命令之前运行java文件或脚本?或者在战争产生之前。



我不确定阶段应该是什么,但基本上在其他人之前查看web.xml以便我可以将其触及制作新的有效

解决方案

你可以使用 exec-maven-plugin 运行程序/脚本(使用 exec目标)或Java程序(使用 java目标)。



紧接之前的阶段是 prepare-package (参见生命周期参考),所以你可以使用它。但您可能更愿意在生命周期的早期生成web.xml(甚至早在 generate-resources )。



<把这些放在一起,你可能会尝试这样的事情:

 < 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>

或者,您可以考虑编写自己的插件,特别是如果您认为这个想法对多个项目有用。


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.

解决方案

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.

这篇关于Maven,在战争即将建成之前运行java方法或脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆