开发者

Maven build a WAR file but build a JAR file first

I have two Maven Projects in Eclipse, both with their own POM.

Project A creates a JAR file.

Project B creates a WAR file.

When I run the "package" command against project B, I would like it to also package project A and then copy the resultant JAR file to an arbitrary location in Project B.

I have tried (and succeeded) in the copy by using the webResources value in the maven-war-plugin, like so:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.0.2</version>
  <configuration>
    <webResources> 
      <resource> 
        <directory>../ProjectA/target</directory> 
        <targetPath>.</targetPath>
        <includes>
          <include>开发者_如何学Go;ProjectA*.jar</include>
        </includes>
        <excludes>
          <exclude>*shaded*.jar</exclude>
        </excludes>
      </resource> 
   </webResources> 

But how can I get the POM for project B to do a build of project A?

An alternate approach that I tried was making project A a dependency of project B so it would be imported into the WEB-INF/lib directory of the WAR and then moving it elsewhere. But this seems a bit messy.

Any help, greatly appreciated.


For this purpose you should create a multi-module build with a structure like this.

  root
   +-- pom.xml
   +-- ProjectA
          +-- pom.xml
   +-- ProjectB
          +-- pom.xml

With a structure like the above you can handle your problem very elegant. Furthermore read about multi-module builds etc. One thing is to use a more up-to-date version of the maven-war-plugin, cause the current version is 2.1.1 and not 2.0.X.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜