Search code examples
javamavenwarearskinny-war

Maven: Let SkinnyWars preserve some libraries


I am using maven to build an ear file with two EJBs and a few web applications. I'd like to use skinny wars, because more wars are likely to follow.

As I understood, the following will remove all *.jar files (except ejb jars) from the WEB-INF/lib directory of all war files:

<dependencies>
  <dependency>
    <groupId>my.domain</groupId>
    <artifactId>project</artifactId>
    <version>${project.version}</version>
    <type>war</type>
  </dependency>

  <!-- Scope: Provided for skinnies. -->
  <dependency>
    <groupId>my.domain</groupId>
    <artifactId>project</artifactId>
    <version>${project.version}</version>
    <type>pom</type>
  </dependency>
</dependencies>

[..]

 <configuration>
      <version>7</version>
      <defaultLitBundleDir>lib/</defaultLitBundleDir>
      <skinnyWars>true</skinnyWars>
[..]

The problem I have is that will obviously also remove all webjars. Webjars are web libraries (css, JS, etc.) which are packaged inside jar files like this:

With any Servlet 3 compatible container, the WebJars that are in the WEB-INF/lib directory are automatically made available as static resources. This works because anything in a META-INF/resources directory in a JAR in WEB-INF/lib is automatically exposed as a static resource.

Source: http://www.webjars.org/documentation#servlet3

I really like this idea. So now, when all jars are moved to myear!/lib/webjar, the containing files are not exposed anymore. :-(

I haven't found an option for skinnyWars to NOT exclude certain libraries (like org.webjars::).

If there is another solution, I'd love to see your input.


Solution

  • So, there was an easy solution. As you see from my updated answer, I had the (almost) same dependency of the war file twice: Once as type=war, another one as type=pom, so all dependencies were included in the ear and stripped from the war.

    Now, I could just manually put the shared libraries there, but I was thinking of DRY. So I wanted to go with the mentioned solution. Seems a bit hacky, but works flawlessly.

    But some moments later, I clicked on the wrong link in the webjars documentation for Servlet2, which I am not using.

    It works by having another dependency, which consists of only one Servlet. This servlet rewrites/passes requests to the corresponding files in META-INF/resources. I thought this may be working for my situation as well.

    So I included the dependency seen on the servlet2 documentation and added the corresponding parts to the web.xml file. And not it's working as expected.