Add Maven to Docker Oracle Linux Image

I spent way too much time figuring out how to install Maven on Oracle Linux from behind a proxy. This is the solution I came up with.

Sample Dockerfile

FROM oraclelinux:6
MAINTAINER Kyle Ryan <kyleus@gmail.com>

# Uncomment and update if you are behind a proxy
#RUN export http_proxy=http://user:pass@proxyurl
#RUN export https_proxy=http://user:pass@proxyurl

# Install Maven
RUN yum -y install wget
RUN wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
RUN yum -y install apache-maven

# Uncomment this in order to connect to maven repos
#ADD settings.xml /root/.m2/settings.xml

Sample Maven settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 
    <proxies>
        <proxy>
            <active>true</active>
            <protocol>http</protocol>
            <username>user</username>
            <password>pass</password>
            <host>proxyURL</host>
        </proxy>
    </proxies>
</settings>

Maven Publish 2nd Client Jar From Same Repo

I recently need to be able to publish two artifacts from one maven module within a multi module build. I fumbled around for a while looking for the best way to handle this. The key was defining the classifier under configuration.

Maven pom.xml

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <parent>
        <groupId>net.kyleryan</groupId>
        <artifactId>myproject</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
 
    <artifactId>implementation</artifactId>
    <version>1.0-SNAPSHOT</version>
 
    <name>GSSMFrameworkV2</name>
 
    <dependencies>        
        <!-- dependencies -->
    </dependencies>
 
    <build>
        <!-- Define the classes that will make up the client jar -->
        <plugins>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <executions>
                    <execution>
                        <id>client</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classifier>client</classifier>
                            <includes>
                                <include>net/kyleryan/exception/FrameworkExceptionHandler.class</include>
                                <include>net/kyleryan/exception/UserException.class</include>
                                <include>net/gm/gssm/framework/ui/controller/MyController.class</include>
                                <include>net/gm/gssm/framework/ui/handler/MyHandler.class</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
 
</project>

Referencing the client jar in another module looks like this.

Dependency Example

<dependency>
    <groupId>net.kyleryan</groupId>
    <artifactId>implementation</artifactId>
    <version>1.0-SNAPSHOT</version>
    <classifier>client</classifier>
</dependency>

JRebel and Maven Resource Filtering

Today, I was having an issue running an ear on a WLS application server. The build for the ear is a multi-module maven build. One of the modules contains a lot of properties files. Several of the property files have configuration information that changes based on environment. For example, a web service endpoint can change between environments.

Maven has is able to do property replacement as part of the packaging process.

# Web Service endpoint
hello_world_url=http://${ws.host}/HelloWorld?wsdl</pre> 

Maven pom.xml

<properties>
  <ws.host>helloworld.com</ws.host>
</properties>
 
<build>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
    </resource>
  </resources>
 
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-resources-plugin</artifactId>
      <version>2.7</version>
      <configuration>
        <encoding>UTF-8</encoding>
      </configuration>
    </plugin>
  </plugins>
</build>

The issue is that JRebel will default to using the properties in src/main/resources that contain the replacement string ${ws.host} which will not resolve to a valid url. This will result calls to the web service to fail.

One way to fix this is by excluding the properties files containing replacement strings from being looked at by JRebel. This can be done by editing the jrebel.xml. The syntax for defining the property files to be excluded follows ant style globbing.

Rebel.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
 
    <classpath>
        <dir name="/configuration/src/main/resources">
              <exclude name="config.properties"/>
              <exclude name="**/report_labels*.properties"/>
        </dir>
    </classpath>
 
</application>