0

I want to migrate about 15 Ant projects to Maven.

Current build with Ant:

project-1
project-2 (needs project-3 as dependency)
project-3
project-webresources (contains web resources needed by ALL other projects)
project-WAR (empty target project)

(project-1, project-2, project-3 contain additional web resources)

Now, different WARs have to be built:

For Deployment 1 (contains project-1 and project-webresources):
Java sources from project-1 are compiled and copied to project-WAR/WEB-INF/classes
Web resources from project-webresources and project-1 are copied to project-WAR/

For Deployment 2 (contains project-1, project-2, project-3 and project-webresources):
Java sources from project-1, project-2, project-3 are compiled an copied to project-WAR/WEB-INF/classes
Web resources from project-webresources, project-1, project-2 and project-3 are copied to project-WAR/

My plan to realize it with Maven:
The projects become modules and for every deployment I create a project which holds the needed modules and one target WAR artifact. For the project-webresources I use maven overlays.

Build-deployment-1:

(mvn install here to build the deployment-1 Web archive)

 <packaging>pom</packaging>
 <modules>
      <module>project-1</module>
      <module>project-webresources</module>
      <module>WAR-deployment-1</module>
 </modules>

WAR-deployment-1:

<packaging>jar</packaging>
<dependency>
  <groupId>com.groupId</groupId>
  <artifactId>project-webresources</artifactId>
  <version>1.0-SNAPSHOT</version>
  <type>war</type>
  <scope>runtime</scope>
</dependency>

<dependency>
  <groupId>com.groupId</groupId>
  <artifactId>artifact-1</artifactId>
  <version>1.0-SNAPSHOT</version>
</dependency>

For the second WAR there will be projects like Build-deployment-2 and WAR-deployment-2 and so on which use other module combinations.

My problem:

What is the best way to copy all web resources from project-1 to WAR-deployment-1? If I use maven-resources-plugin in project-1 to copy resources to WAR-deployment-1 the target directory is hard coded to WAR-deployment-1. What if project-1 is part of build-deployment-2 and files have to be copied to WAR-deployment-2?! Can I use build properties for this? Or is the assembly plugin a solution?

Ginkgochris
  • 455
  • 4
  • 25
  • What type of projects are project 1/2/3? WARs? Jars? if jars, why would they contain webresources? Certainly your WARDeployment should be of type `war`. – blackbuild Apr 11 '14 at 07:52
  • That's exactly the problem ;-) project 1/2/3 should be JARs but they also contain web resources which have to be copied to the resulting war IF the module is used! This is because of a proprietary framework and Ant doesn't differentiate between JAR and WAR. I found out that project-webresources should be an maven-overlay so that it is automatically merged into the final WAR. I could do a hack: Define ALL projects as WAR and then *.class and web resources are copied to the final WAR. ;-) – Ginkgochris Apr 11 '14 at 10:45
  • You should not be moving .class files around. Your war should depend on the jars that they are packaged into. Each war requires a separate pom file -- they are separate modules. Resources within each war are available on the classpath. If a resource is a web resource, then it should be in a war's webapp folder, not a resource folder within a shared library. You can, as you say, use overlays to share resources across multiple wars, through the dependency mechanism. So, web resources only go in webapp directories under war modules, everything else is in jar modules, and don't copy files around. – Software Engineer Apr 11 '14 at 15:38
  • The best solution would be to use web fragments (see my question http://stackoverflow.com/questions/21094708/does-servletcontext-getrealpath-work-with-web-fragments) but it's not possible with this legacy web framework. My hack (packaging everything as WAR) doesn't work too, as these WARs contain java classes which have to be on the classpath for other modules but aren't because they are WARs. ;-) – Ginkgochris Apr 15 '14 at 15:35

0 Answers0