How do I get maven to use the JNLP version naming convention?

845 Views Asked by At

I've been tasked with reducing the download size of one of our webstart apps. I've figured that a decent portion of the download is from all a largish library of jar files, and since we rarely update many of them, it seems the download will be reduced significantly using the JNLP Version Download Protocol. This should stop the continual re-download of the same jars when a new version of the app is released.

Now, the project is build with maven. Part of the process is automatically generating a JNLP file from a velocity template. The resources section of the JNLP file is populated by a $dependencies variable assumedly passed in by maven and looks something like this:

<jar href="lib/mainjar-0.1.40-SNAPSHOT.jar" main="true"/>
<jar href="lib/somejar-1.1.jar"/>
<jar href="lib/someotherjar-1.0.jar"/>
<jar href="lib/anotherjar-1.6.0.jar"/>
 etc...

It seems to me that maven is using its standard naming convention and constructing the jar names from the artifactId and version tags out of the project pom files.

How can I get it to use the JNLP naming convention instead?

I can change the velocity template to cut the $dependencies variable up and re-combine it with the JNLP convention - but that's only halfway what I need since the actual jar names need to be changed too.

1

There are 1 best solutions below

1
On BEST ANSWER

The version download protocol article is about speeding up the check that resources are up to date. Although it may be useful as well, it is not the part that prevents re-downloading of the same files.

Webstart-maven-plugin can take care of versioning of the jars for you and they declare they use the version protocol as well. See http://www.mojohaus.org/webstart/webstart-maven-plugin/jnlp-mojo.html#outputJarVersions

My personal experience differs from what the docs say. It adds the version attribute for jars in the resulting jnlp and does not set the jnlp.versionEnabled property, which seems to be required for the version download protocol. Either way JWS works as I would expect - files are not re-downloaded when their version does not change.

Plugin setup:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>webstart-maven-plugin</artifactId>
    <version>1.0-beta-6</version>
    <dependencies>
        <!--This dependency definition resolves class loading issue on Java 8 -->
        <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>keytool-api-1.7</artifactId>
            <version>1.4</version>
        </dependency>
    </dependencies>

    <executions>
        <execution>
            <phase>process-resources</phase>
            <goals>
                <goal>jnlp-download-servlet</goal>
            </goals>
        </execution>
    </executions>

    <configuration>
        <outputDirectoryName>/</outputDirectoryName>
        <libPath/>

        <sign>
            <keystore>${basedir}/foo-key-store.jks</keystore>
            <storepass>password</storepass>
            <alias>foo-self-signed</alias>
            <verify>true</verify>
        </sign>
        <unsign>true</unsign>

        <jnlpFiles>
            <jnlpFile>
                <inputTemplate>template.vm</inputTemplate>
                <outputFilename>foo.jnlp</outputFilename>

                <jarResources>
                    <jarResource>
                        <groupId>foo.bar</groupId>
                        <artifactId>foo</artifactId>
                        <version>${project.version}</version>
                        <mainClass>foo.bar.Foo</mainClass>
                        <outputJarVersion>false</outputJarVersion>
                    </jarResource>
                </jarResources>
            </jnlpFile>
        </jnlpFiles>

        <gzip>true</gzip>
    </configuration>
</plugin>

Excerpt from the generated foo.jnlp showing the version attribute of a dependency:

<jar href="commons-collections.jar" version="3.2.1"/>

And the file it references is named:

commons-collections-3.2.1.jar