开发者

Maven project for both WAR and standalone server/client

I have a POM-based Java project. It contains a number of servlets for deployment in a WAR. However, in addition to this, I also have classes that launch the application as a standalone using embedded servlet and database environments (for a turnkey development environment). Additionally, there is als开发者_如何学Goo a command-line client for the application.

I would like to have the ability to build the project into both the WAR and two separate executable JARS (one server, one client). I'm not concerned about the JARs/WAR containing some unnecessary code or deps- I just want all 3 to work.

What's the "correct" way to do this with Maven?


Multiple projects is the way to do this. Put the common code in the first project along with the standalone support. Then make a second with war packaging that depends on the first.


You could use assembly plugin to do this. Assembly plugin can package zip or tar.gz archive for you. It's a perfect distribution format for standalone applications. When you configure assembly plugin you could link it to package phase, so application will be packaged in two formats: war and zip.

<plugins>
  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.1</version>
    <executions>
      <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
          <goal>assembly</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜