Skip to main content

Welcome to Geoff Hayward's Weblog

Commenting on Java, JavaFX, Java EE, Joomla, and IoT.

This post is a note on using Maven's 'maven-antrun-plugin' to replace a variable version number in a Dockerfile with the Maven project's version.

The following code replaces this line ADD ./target/application-@{version}.jar application.jar in a Dockerfile with something like ADD ./target/application-1.2.0-SNAPSHOT.jar application.jar. The processed Dockerfile is then saved in the target folder alongside any other artefacts created by Maven.

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
                <target>
                    <copy file="Dockerfile" todir="${project.build.directory}"/>
                    <replace file="${project.build.directory}/Dockerfile" >
                        <replacefilter token="@{version}" value="${project.version}" />
                    </replace>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Once the Dockerfile has been processed a tool such as the Maven 'maven-assembly-plugin' can then package the Dockerfile and other artefacts into a shippable form.

For completeness, here is an example configuration that creates a shippable ZIP ready for AWS's Elastic Beanstalk.

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>make-zip</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <appendAssemblyId>false</appendAssemblyId>
        <descriptors>
            <descriptor>assembly.xml</descriptor>
        </descriptors>
    </configuration>
</plugin>

And here is the corresponding example of the 'filesSets' element from an assembly.xml.

<fileSets>
    <fileSet>
        <directory>${project.build.directory}</directory>
        <includes>
            <include>${project.build.finalName}.jar</include>
        </includes>
        <outputDirectory>target</outputDirectory>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}</directory>
        <includes>
            <include>Dockerfile</include>
        </includes>
        <outputDirectory>.</outputDirectory>
    </fileSet>
    <fileSet>
        <directory>${basedir}</directory>
        <includes>
            <-- other stuff from the base directory -->
        </includes>
        <outputDirectory>.</outputDirectory>
    </fileSet>
</fileSets>

I hope this helps you.



Read

I have been trying to put an older embedded Jetty served application onto Java 8. The application's JSP files where, however, not compiling. This delayed having the benefits Java 8 brings to development.

After a lot of digging I discovered that the Mavan 'org.mortbay.jetty' namespace (a.k.a. groupid) had been superseded by 'org.eclipse.jetty'. The newer development and fixes by the Jetty project are in the later namespace. Therefore, by replacing the old 'org.mortbay.jetty' dependency:

<dependency>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jsp-2.1-glassfish</artifactId>
  <version>9.1.02.B04.p0</version>
</dependency>

with the new 'org.eclipse.jetty'. dependency:

<dependency>
  <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-jsp</artifactId>
  <version>9.3.0.M1</version>
</dependency>

the JSP's compile and the older project now works with Java 8.



Read

Mailing List


Responsive Media

With the ResponsiveMedia plugin for Joomla it is easy to add 3rd party content from YouTube, Vimeo, and Instagram right in to any Joomla! article.

ResponsiveMedia