Fork me on GitHub

Jawr maven plugin

The goal of the Jawr maven plugin is to simplify the use of the bundle preprocessing in the maven build lifecycle. If you have not read the documentation of the bundle preprocessing, please take a look at it before continuing.

Prerequisites

The Jawr maven plugin requires at least maven 2.0.1

Usage

The Jawr maven plugin use the following properties:

  • rootPath The path to the root of the web application. Default value: \$project.build.directory/\$project.build.finalName
  • tempDirPath The path to the temporary directory for JAWR. Default value: \$project.build.directory/jawr/temp
  • destDirPath The path to the destination directory. Default value: \$project.build.directory/jawr/bundles
  • servletsToInitialize The comma separated list of servlet name to initialize Default value: ""
  • springConfigFiles the comma separated list of spring configuration files, which will be used to initialize the Jawr spring controller. This property accepts any spring resource location definition like classpath:…, file:…, etc
  • generateCDNFiles The flag indicating if we should generate the CDN files or not Default value: true
  • keepUrlMapping The flag indicating if we want to keep the jawr URL mapping or if we rewrite it to remove resource hashcode. Default value: false
            <plugin>
                    <groupId>net.jawr.tools</groupId>
                    <artifactId>jawr-maven-plugin</artifactId>
                    <version>3.8</version>
                    <executions>
                      <execution>
                        <!-- Use this phase so that we could deal with the war folder just before the war package -->
                        <phase>prepare-package</phase>
                        <goals>
                          <goal>bundle</goal>
                        </goals>
                      </execution>
                    </executions>
                    <configuration>
                        <generateCDNFiles>true</generateCDNFiles>
                    </configuration>
              </plugin>

For the spring MVC projects, you can use:

            <plugin>
                    <groupId>net.jawr</groupId>
                    <artifactId>maven-jawr-plugin</artifactId>
                    <version>1.0</version>
                    <executions>
                      <execution>
                        <!-- Use this phase so that we could deal with the war folder just before the war package -->
                        <phase>prepare-package</phase>
                        <goals>
                          <goal>bundle</goal>
                        </goals>
                      </execution>
                    </executions>
                    <configuration>
                        <generateCDNFiles>true</generateCDNFiles>
                        <springConfigFiles>classpath:/spring-jawrConfig.xml,/WEB-INF/jawr-controllers.xml</springConfigFiles>
                    </configuration>
              </plugin>

You could launch the bundling process directly using the maven command:

            mvn jawr:bundle

Classpath issue

As you know, the bundle processor fakes the server startup. In the current implementation, the bundle processor will add the WEB-INF/lib directory in the classpath. But you could face some issue, if you are using some jar files which are defined in the application server itself.

To resolve this issue, you can use the classpath property in the plugin definition like below:

        <plugin>
                <groupId>net.jawr.tools</groupId>
                <artifactId>jawr-maven-plugin</artifactId>
                <version>3.8</version>
                <executions>
                  <execution>
                    <!-- Use this phase so that we could deal with the war folder just before the war package -->
                    <phase>prepare-package</phase>
                    <goals>
                      <goal>bundle</goal>
                    </goals>
                  </execution>
                </executions>

                <!-- 
                Add jars as the dependencies of the plugin, so it will be accessible in the classpath 
                during the Jawr maven plugin execution 
                -->

                <dependencies>
                        <dependency>
                                <groupId>com.mycompany</groupId>
                                <artifactId>my-artifact</artifactId>
                                <version>1.0</version>
                        </dependency>
                </dependencies>    
                <configuration>
                    <generateCDNFiles>true</generateCDNFiles>
                </configuration>
          </plugin>