Hardcore DevOps: Building A Portable Weblogic Client on the CLI
Written by Nikos Vaggalis   
Monday, 18 September 2017
Article Index
Hardcore DevOps: Building A Portable Weblogic Client on the CLI
CLI to the rescue
Dealing with dependencies
One fat jar

CLI to the rescue

So back to our client calling the web service example, the workflow that I adopted on the single development machine was to install Maven, access the Oracle Maven repository and then compile everything into one self-contained, stand-alone fat jar.

 

What is Maven


Maven is a tool that can be used for building and managing any Java-based project.Maven’s primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal there are several areas of concern that Maven attempts to deal with:

  • Making the build process easy
  • Providing a uniform build system
  • Providing quality project information
  • Providing guidelines for best practices development
  • Allowing transparent migration to new features

 

Step 1 - Install Maven (as user 'Root')
There are some very good instructions on the web so I refer you there:

If you're on Ubuntu, follow here

If on CentOS, follow here

Step 2 - Install the Wagon provider


By default, Maven uses the wagon-http component to access remote repositories including the Oracle Maven Repository. Since the Oracle Maven Repository is protected by Oracle's Single Sign-On (SSO) technology, the Oracle Maven Repository requires a version of the wagon-http component that supports authentication with an enterprise-grade SSO solution. Prior to wagon-http version 2.8, the wagon-http component did not support the necessary configuration to be able to handle SSO-style authentication. As such, the Oracle Maven Repository requires the use of wagon-http 2.8 (or later).

So let's download version 2.8 or a newer one.In anycase, make sure that you move the downloaded JAR file to the 'M2_HOME/lib/ext/' directory.

 

Step 3 - Amend 'settings.xml'
The file '/opt/maven/conf/settings.xml' contains the configuration that Maven will use in order to resolve dependencies and build projects.As Weblogic's dependencies are hosted on the Oracle Maven repository or it's Nexus mirror only, we'll also have to add a reference to it. Apart from a veil of mystery surrounding it, the other issue with the official Oracle Maven repository is that it is not indexable thus it can't be browsed in order to check out the dependencies.

 

oracle maven

 

The sections of 'settings.xml' we have to touch follow.First of all if there's a local proxy server we must tell Maven.In this case, our proxy does not require authentication  and it's there for the NAT only:

 

<!-- proxies
This is a list of proxies which can be used on this machine to connect to the network. Unless otherwise specified (by system property or command-line switch), the first proxy specification in this list marked as active will be used.-->  

 <proxies>

 <proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username/>
<password/>
<host>proxy.myorg.com</host>
<port>8080</port>
<nonProxyHosts></nonProxyHosts>
</proxy>
</proxies>

 

Then the Servers section:

 

<!-- servers
This is a list of authentication profiles, keyed by the server-id used within the system.Authentication profiles can be used whenever maven must make a connection to a remote server.  -->
 

<servers>
<server>
<id>Oracle_Maven_Repo</id>
<username>Oracle_Account_User</username>
<password>Oracle_Account_Password</password>
<configuration>
<basicAuthScope>
<host>ANY</host>
<port>ANY</port>
<realm>OAM 11g</realm>
</basicAuthScope>
<httpConfiguration>
<all>
<params>
<property>
<name>http.protocol.allow-circular-redirects</name>
<value>%b,true</value>
</property>
</params>
</all>
</httpConfiguration>
</configuration>
</server>
</servers>


Replace 'Oracle_Account_User' and 'Oracle_Account_Password' with your own.If you have none then you must first open an account at oracle.com.

And the Profiles section:

 

<!-- profiles
   This is a list of profiles which can be activated
   in a variety of ways, and which can modify
   the build process. Profiles provided in the settings.xml
   are intended to provide local machine-
   specific paths and repository locations which
   allow the build to work in the local environment.
   --> 

<profiles>
<profile>
<id>Oracle_Maven_Profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>Oracle_Maven_Repo</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://maven.oracle.com</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven.oracle.com</id>
<url>https://maven.oracle.com</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

Step 4 - Creating the actual project from scratch (as user 'Test')
After taking care of the Maven setup, we now have to focus on the project itself.Maven supports the concept of the 'archetype', a templating toolkit that generates the boileplate project structure and code.In this case we start simple, with 'maven-archetype-quickstart'.

Archetypes adhere to the typical artifact definitions found on the Maven repository. Wagon, for example is defined as:

 


<!-- https://mvnrepository.com/artifact/org.apache.maven.wagon/
wagon-http-shared -->
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-shared</artifactId>
<version>2.8</version>
</dependency>

while our custom project's definition is:


<dependency>
<groupId>com.wlogic.client</groupId>
<artifactId>wlogicclient </artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

Running:


$ mvn archetype:generate -DgroupId=com.wlogic.client
-DartifactId=wlogicclient -Dpackage=com.wlogic.client
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false

in verbose mode, logs:

Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.jar (5 KB at 38.2 KB/sec)
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.wlogic.client
[INFO] Parameter: packageName, Value: com.wlogic.client
[INFO] Parameter: package, Value: com.wlogic.client
[INFO] Parameter: artifactId, Value: wlogicclient
[INFO] Parameter: basedir, Value: /home/test
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /home/test/wlogicclient
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:36 min
[INFO] Finished at: 2017-08-29T15:33:49+03:00
[INFO] Final Memory: 17M/153M
[INFO] ------------------------------------------------------------------------

 

and generates the following project directory structure:

 

wlogicclient
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- com
    |           `-- wlogic
    |               `-- client
    |                   `-- App.java
    `-- test
        `-- java
            `-- com
                `-- wlogic
                    `-- client
                        `-- AppTest.java
11 directories, 3 files

 

Simply, the production source is placed under '/src/main/java/', while the test source is placed under '/src/test/java/'.



Last Updated ( Monday, 18 September 2017 )