Wednesday, February 5, 2014

Playing Around with WebLogic Maven Plug-In

Packaged with WebLogic 12c wls-maven-plugin let’s you install, start and stop servers, create domain, execute WLST scripts, compile and deploy applications. The plug-in works with Maven 2.x and 3.x.
WebLogic 12c can be downloaded from Developers version has around  180MB (zip archive).  To install the plugin we need first to extract wls-maven-plugin.jar.pack and pom.xml

$unzip ~/Downloads/ wls12120/wlserver/server/lib/wls-maven-plugin.jar.pack

$unzip ~/Downloads/ wls12120/wlserver/server/lib/pom.xml

Now, let’s unpack the jar file:

$unpack200 -r wls12120/wlserver/server/lib/wls-maven-plugin.jar.pack wls12120/wlserver/server/lib/wls-maven-plugin.jar

Install the plug-in in the local repository

$cd wls12120/wlserver/server/lib/

$mvn install
$mvn install:install-file –Dfile=wls-maven-plugin.jar –DpomFile=pom.xml

Modify global or user settings.xml to add the plug-in group id to the default groups. You can find the location of settings.xml by running:

$mvn –X | grep settings

Usually, user settings are located in ~/.m2/settings.xml. For the global configuration file look in the Maven installation directory. For example: ~/apache-maven-3.1.1/conf/ directory/settings.xml.

Add the following lines:


Launch installation of WebLogic Server:

$mvn wls:install -DartifactLocation=/Users/<your_user_name>/Downloads/

Set JVM Settings for the WebLogic domain that will be created. This is necessary especially for 64bit JVMs. These settings are modifying the size of initial heap size, max heap size and, very important, perm gen space. You can do that by setting USER_MEM_ARGS environment variable before starting the server:

$export USER_MEM_ARGS="-Xms256m -Xmx=512m -XX:CompileThreshold=800 -XX:PermSize=128m -XX:MaxPermSize=256m"

Create domain:
$mvn wls:create-domain -DdomainHome=./Domains/domain1 -DmiddlewareHome=./Software/wls12120 -Duser=weblogic -Dpassword=welcome1

Start server:
$mvn wls:start-server  -DdomainHome=./Domains/domain1 -DmiddlewareHome=./Software/wls12120

You can stop the server by running:
$mvn wls:stop-server -DdomainHome=./Domains/domain1 -DmiddlewareHome=./Software/wls12120 -Duser=weblogic -Dpassword=welcome1

Let’s create now a JaveEE application and deploy it to the newly created domain. For the application we will use Maven arhchetypes. First the root POM (Project Object Model):

$mvn archetype:generate -Dversion=1.0-SNAPSHOT -DgroupId=com.flaviussana.demo -DartifactId=DemoApp -DarchetypeArtifactId=pom-root -DarchetypeGroupId=org.codehaus.mojo.archetypes

In the DemoApp directory created run to generate the EAR project:

$mvn archetype:generate -Dversion=1.0-SNAPSHOT -DgroupId=com.flaviussana.demo -DartifactId=DemoApp-EAR -DarchetypeArtifactId=ear-javaee6 -DarchetypeGroupId=org.codehaus.mojo.archetypes

Create an EJB mode and a WebApp module:

$mvn archetype:generate -Dversion=1.0-SNAPSHOT -DgroupId=com.flaviussana.demo -DartifactId=DemoApp-EJB -DarchetypeArtifactId=ejb-javaee6 -DarchetypeGroupId=org.codehaus.mojo.archetypes

$mvn archetype:generate -Dversion=1.0-SNAPSHOT -DgroupId=com.flaviussana.demo -DartifactId=DemoApp-WAR -DarchetypeArtifactId=webapp-javaee6 -DarchetypeGroupId=org.codehaus.mojo.archetypes

Set the dependencies in EAR pom.xml:

Create a simple EJB Bean:HelloWorldEJB

package com.flaviussana.demo;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

 * Session Bean implementation class HelloWorldEJB
public class HelloWorldEJB {

     * Default constructor.
    public HelloWorldEJB() {
        // TODO Auto-generated constructor stub
    public String sayHello(String name) {
       return "Hello " + name + "!";


Build the application by running “mvn install” in parent project directory then deploy the application by running in DemoApp-EAR:

$mvn wls:deploy -Dname=DemoApp-EAR -DmiddlewareHome=/Users/<your_user_name>/tmp/Oracle/Software/wls12120 -DdomainHome=/Users/<your_user_name>/tmp/Oracle/Domains/domain1

Test the application by going to:

Another interesting feature of the WebLogic Maven plugin is the “wlst” goal that can be used to execute WLST (WebLogic Scripting Tool) scripts. For example you can run to create resources like DataSources or queues:

$mvn wls:wlst –Duser=weblogic –Dpassword=welcome1 –

No comments: