Search code examples
maventomcatosgimaven-bundle-plugin

Pack ServletContainerInitializers from different bundles to a single OSGi bundle


I'm creating an OSGi bundle which consist of following dependencies

<artifactId>tomcat-dbcp</artifactId>
<artifactId>tomcat-embed-core</artifactId>
<artifactId>tomcat-embed-jasper</artifactId>
<artifactId>tomcat-embed-websocket</artifactId>
<artifactId>tomcat-jasper</artifactId>
<artifactId>ecj</artifactId>

I want to pack the SCIs in both websocket and jasper.

My IncludeResource section is as follows

<Include-Resource>
         {maven-resources},
         @tomcat-jasper-${version.tomcat}.jar!/META-INF/*,
         @tomcat-embed-websocket-${version.tomcat}.jar!/META-INF/*,
         src/main/resources
</Include-Resource>

Problem here is I'm only getting websocket SCi. I think jasper resources get overridden by the websocket resources. Depend on the order I specify them.

How can I put both resource in the same bundle?


Solution

  • I found the answer for this. You can use maven-shade-plugin for this.

    e.g. In My scenario I can pack both SCIs as follows

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
              </transformers>
            </configuration>
          </execution>
        </executions>
    </plugin>