Adding an applet in a submodule to a WAR file in Maven
Asked Answered
C

3

6

I've got a Maven2 project with two submodules, laid out like this:

parentproject
|---war-file-project
|---applet-project

The POMs in each of them have the appropriate parent-module relationships. The applet-project contains a simple applet and is set up with JAR packaging. The war-file-project contains a simple WAR file project and is set up with WAR packaging.

When I build, I'd like to make sure that the WAR file contains the resulting JAR file from the applet-project in the /applets directory.

How do I do this?

Ceraceous answered 19/8, 2011 at 11:33 Comment(0)
D
7

To achieve that you can simply use the maven-dependency-plugin to copy the dependency to an appropriate location.

Created a complete example which you can use as a template.

Deutoplasm answered 19/8, 2011 at 12:24 Comment(0)
N
2

Thanks khmarbaise for an excellent template!

I've also found one might want to adjust it with the following changes:

  • add <scope>provided</scope> to the 'supplemental' dependency in war/pom.xml - then supplemental.jar will not be duplicated at /WEB-INF/lib
  • add <stripVersion>true</stripVersion> to the example maven-dependency-plugin configuration - then applet will be in 'supplemental.jar' instead of something like 'supplemenal-0.1.0-SNAPSHOT.jar'
  • change ${project.artifactId}-${project.version} in <outputDirectory> to a more reliable ${project.build.finalName}
Niklaus answered 22/9, 2011 at 8:35 Comment(0)
D
0

You have to define a dependency in the war-project to your applet-project.

<dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>applet-project</artifactId>
  <version>${project.version}</version>
</dependency>
Deutoplasm answered 19/8, 2011 at 12:11 Comment(1)
That will appear to put the JAR file for my applet in WEB-INF/lib, which is not what I want. I'd like it in the root of the WAR file so that it can be downloaded by the user and run in his browser.Ceraceous

© 2022 - 2024 — McMap. All rights reserved.