tags:

views:

247

answers:

2

There are two projects: 1) applet project that outputs jar file 2) web app project that should host the jar file.

After (1) finished building, the applet jar file should be copied into the webapp folder of (2). The purpose is that (2) will host the applet (1) on the Internet.

A lot of examples explain how to use another project as a library dependency. Other examples, show how to use ant plugin to copy files. I am unsure on how to properly set this up, so that 'mvn install' on the parent project will do the copying at the right time.

A: 

Use dependency:copy.

lexicore
A: 

I would declare the applet as a dependency of the webapp, copy it to the webapp just before packaging using the Dependency plugin and its copy goal. The whole solution might looks like this:

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>my-applet</artifactId>
      <version>${project.version}</version>
      <scope>provided</scope> <!-- we don't want the applet in WEB-INF/classes -->
    </dependency>
    ...
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.1</version>
        <executions>
          <execution>
            <id>copy</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>my-applet</artifactId>
                  <version>${project.version}</version>
                  <outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory>
                  <destFileName>the-applet.jar</destFileName>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  </build>
</project>

Declaring the applet as dependency is for the reactor build order (but I'm not 100% sure it is required).

Pascal Thivent
Yep, that worked 100%. You are fast! And, yes, reactor required the dependency (set to provided).
Thomas
@Thomas Glad it was helpful. Thanks for the feedback (and for confirming my little doubt).
Pascal Thivent