Hi,

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] ------------------------------------------------------------------------
[INFO] Building WebLogic Server Maven Plugin 12.1.3.0
[INFO] ------------------------------------------------------------------------
[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/12.1.3.0/wls-maven-plugin-12.1.3.0.jar
[INFO] Installing /PATH/TO/wls12130/wlserver/server/lib/pom.xml to /Users/jsensharma/.m2/repository/com/oracle/weblogic/wls-maven-plugin/12.1.3.0/wls-maven-plugin-12.1.3.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[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"> 

  <pluginGroups> 
    <pluginGroup>com.oracle.weblogic</pluginGroup>
  </pluginGroups>  
</settings>

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] ------------------------------------------------------------------------
[INFO] Building WebLogic Server Maven Plugin 12.1.3.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- wls-maven-plugin:12.1.3.0:help (default-cli) @ wls-maven-plugin ---
[INFO] 
WebLogic Server Maven Plugin
The following goals are supported by wls-maven-plugin:

appc:
  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. 

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

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

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

install:
  Installs WebLogic Server. 

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

redeploy:
  Redeploys a running application or part of a running application. 

start-app:
  Starts an application deployed on WebLogic Server. 

start-server:
  Starts WebLogic Server. 

stop-app:
  Stops an application. 

stop-server:
  Stops WebLogic Server. 

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

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

wlst:
  WLST wrapper for Maven. 

ws-clientgen:
  A Maven goal to generate client web service artifacts from a WSDL 

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

ws-jwsc:
  A Maven goal to build a JAX-WS web service 


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

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:

<HTML>
	<HEAD>
		<TITLE> Sample Web Application </TITLE>
	</HEAD>
	<BODY>
		<%
			out.println("
<h2>Hello World!!! , Date/Time: "+ new java.util.Date()+"
<h2>");
		%>
	</BODY>
</HTML>

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">
         
  <modelVersion>4.0.0</modelVersion>
  <groupId>middleware.magic</groupId>
  <artifactId>TestWebApp</artifactId>
  <version>1.0</version>
  <packaging>war</packaging>
  <name>TestWebApp</name>
  
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <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 !!! -->
  </properties>  
  
  
  <dependencies>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-web-api</artifactId>
      <version>6.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  
  <build>
   <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
      
      <plugin>
        <groupId>com.oracle.weblogic</groupId> 
        <artifactId>wls-maven-plugin</artifactId> 
        <version>12.1.3.0</version> 
        <configuration> 
          <middlewareHome>${middleware.home}</middlewareHome>
          <adminurl>${admin.server.url}</adminurl>
          <user>${admin.username}</user>
          <password>${admin.password}</password>
          <name>${project.build.finalName}</name>
          <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>          
        </configuration> 
      </plugin>
      
   </plugins>
  </build>
</project>

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:
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WebLogic/Maven/TestWLS_PluginProject

Regards
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.