War with no jars!


In my previous post I spoke about jars.txt and how to add a jar in a WAR virtually and from several sources (mvn, http, file…).

Now to use it in a more enterprise environment you can use the dedicated maven plugin.

Its usage is pretty obvious:

<plugin>
   <groupId>org.apache.openejb.maven</groupId>
   <artifactId>jarstxt-maven-plugin</artifactId>
   <version>4.6.0-SNAPSHOT</version>
   <executions>
     <execution>
       <goals>
         <goal>generate</goal>
       </goals>
    </execution>
  </executions>
</plugin>

This way it will generate a file with the list of maven dependencies. For instance for the following dependencies in your pom.xml:

<dependencies>
  <dependency>
    <groupId>org.apache.openejb</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0-4</version>
    <scope>provided</scope>
  </dependency>

  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-core</artifactId>
    <version>2.10.3</version>
    <exclusions>
      <!-- slf4j needs to be provided with an impl or not provided -->
      <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
  <dependency>
    <groupId>org.apache.deltaspike.core</groupId>
    <artifactId>deltaspike-core-api</artifactId>
    <version>0.3-incubating</version>
  </dependency>
</dependencies>

it will generate the following jars.txt:

mvn:org.apache.camel/camel-core/2.10.3
mvn:org.apache.deltaspike.core/deltaspike-core-api/0.3-incubating

If you want more validation of the dependencies you can activate the hash computation by dependency:

<plugin>
   <groupId>org.apache.openejb.maven</groupId>
   <artifactId>jarstxt-maven-plugin</artifactId>
   <version>4.6.0-SNAPSHOT</version>
   <executions>...</executions>
  <configuration>
    <hashAlgo>MD5</hashAlgo> <!-- MessageDigest algo -->
  </configuration>
</plugin>

And here you get:

mvn:org.apache.camel/camel-core/2.10.3|ea4c4bc2936767a599a7e323440701c8|MD5
mvn:org.apache.deltaspike.core/deltaspike-core-api/0.3-incubating|bcf4b9c05c005b7c2524864b5ca50e57|MD5

Some final notes:

 

  • default location of jars.txt is WEB-INF but you can configure it with outputFile parameter
  • In very last TomEE (trunk) the maven dependencies are resolved locally first, if your maven repo is not the default one configure the repo location through openejb.m2.home variable in conf/system.properties
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s