1
votes

In my project I use war overlays. In first base war in src/main/resources I have file my-file.txt. Second war depends on first war. Second war has a code to lookup for my-file.txt on classpath:

Enumeration<URL> urls = MyListener.class.getClassLoader().getResources("my-file.txt");
while (urls.hasMoreElements()) {
    System.out.println("This is my resource:" + urls.nextElement());
}

My output is (mvn jetty:run):

This is my resource:jar:file:/C:/Users/michaldo/.m2/repository/war-plus-war/war1/0.0.1-SNAPSHOT/war1-0.0.1-SNAPSHOT-classes.jar!/my-file.txt

This is my resource:jar:file:/C:/Users/michaldo/workspace-n1/war-plus-war/war2/target/tmp/war1-0_0_1-SNAPSHOT_war1/WEB-INF/lib/war1-0.0.1-SNAPSHOT.jar!/my-file.txt

Can I configure maven jetty plugin and avoid duplication?

My maven-war-plugin configuration (jetty has default configuration):

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <archiveClasses>true</archiveClasses>
        <attachClasses>true</attachClasses>
        <dependentWarExcludes>
            WEB-INF/lib/*-*.jar
        </dependentWarExcludes>
    </configuration>
</plugin>
1

1 Answers

1
votes

The problem is that dependentWarExcludes is deprecated (and even not supported in maven-war-plugin 3.0

Maven Jetty plugin works as expected when I move exclusion to overlay config:

<build><plugins><plugin>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <overlays>
      <overlay>
        <groupId>war-plus-war</groupId>
          <artifactId>war1</artifactId>
          <excludes><exclude>
              WEB-INF/lib/*-*.jar
          </exclude></excludes>
        </overlay>
     </overlays>
   </configuration>
</plugin></plugins></build>