As part of this example we will talk about the new “wls-maven-plugin” which is added as part of WebLogic 12c installation. This plugin provides a lots of additional facilities compared to the older “weblogic-maven-plugin” plugin. With the help of “wls-maven-plugin” plugin we can install, start and stop servers, create domains, execute WLST scripts, and compile and deploy applications.

The wls-maven-plugin requires a local WebLogic Server installation. For more information on this please refer to the following link: https://docs.oracle.com/cd/E24329_01/web.1211/e24368/maven.htm#WLPRG692

Update:10-Nov-2015 Unfortunately this plugin is removed in WebLogic 12.2.1, See the review: https://community.oracle.com/message/13400268

Installing “wls-maven-plugin”

Step-1). Open a terminal and run the following command:

$ export M2_HOME=/PATH/TO/apache_maven_3.2.3
$ export JAVA_HOME=/PATH/TO/jdk1.8.0_60
$ export PATH=$JAVA_HOME/bin:/PATH/TO/apache_maven_3.2.3/bin:$PATH

$ export MW_HOME=/PATH/TO/wls12130
$ cd $MW_HOME/wlserver/server/lib
$ mvn install -Dfile=wls-maven-plugin.jar -DpomFile=pom.xml

Step-2). Now install the wls-maven-plugin inside the local maven repository which is by default “~/.m2/repository”. In this case it will be placed inside the following dir “~/.m2/repository/com/oracle/weblogic/wls-maven-plugin”

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

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building WebLogic Server Maven Plugin
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ wls-maven-plugin ---
[INFO] Installing /PATH/TO/wls12130/wlserver/server/lib/wls-maven-plugin.jar to /Users/jsensharma/.m2/repository/com/oracle/weblogic/wls-maven-plugin/
[INFO] Installing /PATH/TO/wls12130/wlserver/server/lib/pom.xml to /Users/jsensharma/.m2/repository/com/oracle/weblogic/wls-maven-plugin/
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.289 s
[INFO] Finished at: 2015-10-20T09:51:47+05:30
[INFO] Final Memory: 7M/245M
[INFO] ------------------------------------------------------------------------

Defining “pluginGroup” via global “settings.xml” file.

Step-3). Make sure to add the following “com.oracle.weblogic” in your “~/.m2/settings.xml” file:

<?xml version="1.0" encoding="UTF-8"?> 
<settings xmlns="http://maven.apache.org/settings/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> 


Running the “mvn wls:help” command

Step-4). Once the “pluginGroup” is configured then from now on in this machine any time and from any directory we will be able to run the following wls maven task (For Example “mvn wls:help“):

$ cd /ANY/Directory/Of/Your/Choice
$ export M2_HOME=/PATH/TO/apache_maven_3.2.3
$ export JAVA_HOME=/PATH/TO/jdk1.8.0_60
$ export PATH=$JAVA_HOME/bin:/PATH/TO/apache_maven_3.2.3/bin:$PATH

$ mvn wls:help

Output of the above command should be something like following:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building WebLogic Server Maven Plugin
[INFO] ------------------------------------------------------------------------
[INFO] --- wls-maven-plugin: (default-cli) @ wls-maven-plugin ---
WebLogic Server Maven Plugin
The following goals are supported by wls-maven-plugin:

  Generates and compiles the classes needed to deploy EJBs and JSPs to 
  WebLogic Server. Also validates the deployment descriptors for compliance 
  with the current specifications at both the individual module level and 
  the application level. 

  Deploys WebLogic Server applications and modules. Supports all deployment 
  formats, such as WAR, JAR, etc. 

  Create a domain for WebLogic Server using the default domain template. 
  For more complex domain creation use the WLST goal. 

  Lists all the goals supported by the <code>wls-maven-plugin</code>. 

  Installs WebLogic Server. 

  Lists the deployment names for applications and standalone modules 
  deployed, distributed, or installed in the domain. 

  Redeploys a running application or part of a running application. 

  Starts an application deployed on WebLogic Server. 

  Starts WebLogic Server. 

  Stops an application. 

  Stops WebLogic Server. 

  Undeploys the application from WebLogic Server. Stops the deployment unit 
  and removes staged files from target servers. 

  Updates an application's deployment plan by redistributing the plan files 
  and reconfiguring the application based on the new plan contents. 

  WLST wrapper for Maven. 

  A Maven goal to generate client web service artifacts from a WSDL 

  A Maven goal to generate a set of artifacts and a partial Java 
  implementation of the Web service from a WSDL. 

  A Maven goal to build a JAX-WS web service 

For detailed help on a goal, use -Dgoal=<goal-name> -Ddetail=true options.
[INFO] ------------------------------------------------------------------------

Creating a Simple WebApp and Deploy using plugin

Now we will go one step ahead and deploy a simple web application to WebLogic 12c using this plugin.

Step-5). Create a directory structure like following in anywhere your file system :

mkdir TestWLS_PluginProject
cd  TestWLS_PluginProject
mkdir -p src/main/webapp

Step-6). Now create a simple JSP “index.jsp” inside the “TestWLS_PluginProject/src/main/webapp” as following:

		<TITLE> Sample Web Application </TITLE>
<h2>Hello World!!! , Date/Time: "+ new java.util.Date()+"

Step-7). The most important part, Create the following kind of “TestWLS_PluginProject/pom.xml” file, Which will use the “wls-maven-plugin”. In the following pom.xml make sure to change the “CHANGE ME !!!” section with your own environment specific data.

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <middleware.home>/Users/jsensharma/NotBackedUp/Installed/wls12130</middleware.home>  <!-- CHANGE ME !!! -->
    <admin.server.url>t3://localhost:7001</admin.server.url>  <!-- CHANGE ME !!! -->
    <admin.username>weblogic</admin.username>  <!-- CHANGE ME !!! -->
    <admin.password>weblogic1</admin.password>  <!-- CHANGE ME !!! -->


Step-8). Now build and deploy the application using the following command:

$ export M2_HOME=/PATH/TO/apache_maven_3.2.3
$ export JAVA_HOME=/PATH/TO/jdk1.8.0_60
$ export PATH=$JAVA_HOME/bin:/PATH/TO/apache_maven_3.2.3/bin:$PATH
cd  TestWLS_PluginProject

### To deploy application
mvn clean install wls:deploy

### To undeploy application
mvn wls:undeploy

This demo is available in the following link:

Jay SenSharma

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.