wls-maven-plugin: WebLogic 12c Maven Plugin Usage (TOTD #177)


Oracle WebLogic Server 12c provides full Java EE 6 platform support. The screencast #39 shows how to build a complete application using NetBeans. The self-paced hands-on lab provides detailed instructions on the same as well. The Maven support in WebLogic 12c is much more improved. Steve Button and Markus Eisele wrote detailed blogs on how/what/why of Maven support in WebLogic. This Tip Of The Day (TOTD) will provide a quick overview of how to get started with using the maven plugin for deploying a Java EE 6 web application.

  1. Download and install WebLogic 12c using the zip installer as explained in TOTD #174.
  2. The Maven plugin can be installed using "$MW_HOME/wlserver/server/lib/wls-maven-plugin.jar". Change the directory to "$MW_HOME/wlserver/server/lib" and give the following commands:
    mvn install
    mvn install:install-file –Dfile=wls-maven-plugin.jar -DpomFile=pom.xml
  3. The maven plugin usage can be seen by giving the following command:
    mvn com.oracle.weblogic:wls-maven-plugin:help
    Or add the following to "~/.m2/settings.xml":
    <pluginGroups>     
    <pluginGroup>com.oracle.weblogic</pluginGroup>
    </pluginGroups>
    And then give the following command:
    mvn wls:help
    to see the output as:
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building wls-maven-sample 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- wls-maven-plugin:12.1.1.0:help (default-cli) @ wls-maven-sample ---
    [INFO]
    WebLogic Server Maven Plugin
    The following goals are supported by wls-maven-plugin:

    appc:
    The appc compiler generates and compiles the classes needed to deploy
    EJBs and JSPs to WebLogic Server. It also validates the deployment
    descriptors for compliance with the current specifications at both the
    individual module level and the application level.

    deploy:
    To deploy a weblogic server application (supports all formats 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:
    Provides a list of all the goals supported by the wls-maven-plugin

    install:
    Install WebLogic Server

    list-apps:
    Lists the deployment names for applications and stand-alone modules
    deployed distributed, or installed to the domain

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

    start-app:
    Starts an application deployed on weblogic server.

    start-server:
    Start WebLogic Server

    stop-app:
    Stops an application

    stop-server:
    Stop 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


    For detailed help on a goal, use -Dgoal=<goal-name> -Ddetail=true options.
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.794s
    [INFO] Finished at: Thu May 03 06:38:23 IST 2012
    [INFO] Final Memory: 8M/125M
    [INFO] ------------------------------------------------------------------------
    More details about each goal can be found using the following command:
    mvn wls:help -Dgoal=<GOAL> -Ddetail=true
    For example:
    mvn wls:help -Dgoal=install -Ddetail=true
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Maven Stub Project (No POM) 1
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- wls-maven-plugin:12.1.1.0:help (default-cli) @ standalone-pom ---
    [INFO]
    WebLogic Server Maven Plugin
    The following goals are supported by wls-maven-plugin:

    install:
    Install WebLogic Server

    Available Parameters:

    installCommand:
    The command to use to install the product when using an
    'executable' installer. The following macros are supported -
    @INSTALLER_FILE@ - the path to the installer file, @JAVA_HOME@ -
    path to the java home. eg: @JAVA_HOME@ -Xms512m -Xmx1024m -jar
    @INSTALLER_FILE@ one two

    artifactLocation:
    The address of the artifact. This can be one of the following -
    1) A ':' separated maven coordinates of the form (groupId:artifac-
    tId:packaging:classifier:version) 2) A file on the local system
    (/home/prash/myapps/helloworld.war)3) A remote http url
    (http://foo/a/b.zip)

    middlewareHome:
    The home directory for Oracle WebLogic Server or Fusion
    Middleware installation. Required unless WLS was installed in the
    default location selected by the WLS Maven Plugin's install goal.

    domainHome:
    Location of WLS domain

    localRepository:
    The absolute path of a local maven repository.

    artifactFactory:
    The artifactFactory is used to locate an artifact with a
    groupId:artifactId:artifactName:version in the remote Repository
    as provided by the remoteRepsitories parameter.

    artifactResolver:
    Artifactresolver resolves the artifact from the remote
    repository. Downloads an updated version of the artifact if
    present in the remote repo.



    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.889s
    [INFO] Finished at: Wed May 02 17:35:46 PDT 2012
    [INFO] Final Memory: 6M/89M
    [INFO] ------------------------------------------------------------------------

  4. Build a Java EE 6 application
    1. Create a Java EE 6 Maven web application as:
      mvn archetype:generate
      -DarchetypeGroupId=org.codehaus.mojo.archetypes
      -DarchetypeArtifactId=webapp-javaee6 -DgroupId=example
      -DartifactId=wls-maven-sample -DarchetypeVersion=1.5
      -DinteractiveMode=false
    2. Add a trivial servlet to the sample project by following the screencast #39. The complete source code for the project can be downloaded here.
  5. Add the following code fragment to the generated "pom.xml":
    <plugin>                
    <groupId>com.oracle.weblogic</groupId>
    <artifactId>wls-maven-plugin</artifactId>
    <version>12.1.1.0</version>
    </plugin>
  6. Try some Maven commands in the "wls-maven-sample" directory
    1. The server can be started as:

      mvn wls:start-server
      -DmiddlewareHome=/Users/arungup/tools/weblogic/12c
      -DdomainHome=/Users/arungup/tools/weblogic/mydomain

      [INFO] Scanning for projects...
      [INFO]
      [INFO] ------------------------------------------------------------------------
      [INFO] Building wls-maven-sample 1.0-SNAPSHOT
      [INFO] ------------------------------------------------------------------------
      [INFO]
      [INFO] --- wls-maven-plugin:12.1.1.0:start-server (default-cli) @ wls-maven-sample ---
      [INFO] ++====================================================================++
      [INFO] ++ wls-maven-plugin: start-server ++
      [INFO] ++====================================================================++
      .[INFO] Starting server in domain: /Users/arungup/tools/weblogic/mydomain
      [INFO] Check stdout file for details: /Users/arungup/tools/weblogic/mydomain/server-922019421247284651.out
      [INFO] Process being executed, waiting for completion.
      ................
      [INFO] Server started successful
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESS
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 16.919s
      [INFO] Finished at: Wed May 02 18:06:22 PDT 2012
      [INFO] Final Memory: 5M/88M
      [INFO] ------------------------------------------------------------------------
    2. Build and deploy the application as:

      mvn wls:deploy
      -DmiddlewareHome=/Users/arungup/tools/weblogic/12c
      -DdomainHome=/Users/arungup/tools/weblogic/mydomain
      -Duser=admin
      -Dpassword=admin007
      -Dsource=/Users/arungup/code/samples/weblogic/wls-maven-sample/target/wls-maven-sample-1.0-SNAPSHOT.war

      [INFO] Scanning for projects...
      [INFO]
      [INFO] ------------------------------------------------------------------------
      [INFO] Building wls-maven-sample 1.0-SNAPSHOT
      [INFO] ------------------------------------------------------------------------
      [INFO]
      [INFO] --- wls-maven-plugin:12.1.1.0:deploy (default-cli) @ wls-maven-sample ---
      [INFO] ++====================================================================++
      [INFO] ++ wls-maven-plugin: deploy ++
      [INFO] ++====================================================================++
      weblogic.Deployer invoked with options: -noexit -user admin -deploy -source /Users/arungup/code/samples/weblogic/wls-maven-sample/target/wls-maven-sample-1.0-SNAPSHOT.war
      <May 3, 2012 8:24:17 AM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, wls-maven-sample-1.0-SNAPSHOT [archive: /Users/arungup/code/samples/weblogic/wls-maven-sample/target/wls-maven-sample-1.0-SNAPSHOT.war], to configured targets.>
      Task 0 initiated: [Deployer:149026]deploy application wls-maven-sample-1.0-SNAPSHOT on myserver.
      Task 0 completed: [Deployer:149026]deploy application wls-maven-sample-1.0-SNAPSHOT on myserver.
      Target state: deploy completed on Server myserver

      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESS
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 7.745s
      [INFO] Finished at: Thu May 03 08:24:18 IST 2012
      [INFO] Final Memory: 11M/130M
      [INFO] ------------------------------------------------------------------------
    3. The application is accessible at localhost:7001/wls-maven-sample-1.0-SNAPSHOT/TestServlet.
    4. Stop the server as:

      mvn wls:stop-server
      -DmiddlewareHome=/Users/arungup/tools/weblogic/12c
      -DdomainHome=/Users/arungup/tools/weblogic/mydomain
      -Duser=admin
      -Dpassword=admin007

      [INFO] Scanning for projects...
      [INFO]
      [INFO] ------------------------------------------------------------------------
      [INFO] Building wls-maven-sample 1.0-SNAPSHOT
      [INFO] ------------------------------------------------------------------------
      [INFO]
      [INFO] --- wls-maven-plugin:12.1.1.0:stop-server (default-cli) @ wls-maven-sample ---
      [INFO] ++====================================================================++
      [INFO] ++ wls-maven-plugin: stop-server ++
      [INFO] ++====================================================================++
      [INFO] Stop server in domain: /Users/arungup/tools/weblogic/mydomain
      [INFO] Process being executed, waiting for completion.
      [INFO] [exec] Stopping Weblogic Server...
      [INFO] [exec]
      [INFO] [exec] Initializing WebLogic Scripting Tool (WLST) ...
      [INFO] [exec]
      [INFO] [exec] Welcome to WebLogic Server Administration Scripting Shell
      [INFO] [exec]
      [INFO] [exec] Type help() for help on available commands
      [INFO] [exec]
      [INFO] [exec] Connecting to t3://localhost:7001 with userid admin ...
      [INFO] [exec] Successfully connected to Admin Server 'myserver' that belongs to domain 'mydomain'.
      [INFO] [exec]
      [INFO] [exec] Warning: An insecure protocol was used to connect to the
      [INFO] [exec] server. To ensure on-the-wire security, the SSL port or
      [INFO] [exec] Admin port should be used instead.
      [INFO] [exec]
      [INFO] [exec] Shutting down the server myserver with force=false while connected to myserver ...
      [INFO] [exec] WLST lost connection to the WebLogic Server that you were
      [INFO] [exec] connected to, this may happen if the server was shutdown or
      [INFO] [exec] partitioned. You will have to re-connect to the server once the
      [INFO] [exec] server is available.
      [INFO] [exec] Disconnected from weblogic server: myserver
      [INFO] [exec] Disconnected from weblogic server:
      [INFO] [exec]
      [INFO] [exec]
      [INFO] [exec] Exiting WebLogic Scripting Tool.
      [INFO] [exec]
      [INFO] [exec] Done
      [INFO] [exec] Stopping Derby Server...
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESS
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 10.847s
      [INFO] Finished at: Thu May 03 06:37:48 IST 2012
      [INFO] Final Memory: 9M/125M
      [INFO] ------------------------------------------------------------------------

Simple, quick, and easy!

Are you building Java EE 6 applications on WebLogic ? With Maven ? Now you can fully integrate the WebLogic lifecycle with your "pom.xml".

The WebLogic Application Development Guide provide detailed documentation on the maven plugin.


Comments:

I think the general approach is:
1. make the plugin available on a public repository.
2. add online documentation that includes goals, usage and examples.

Why is Oracle trying to reinvent the wheel?

Posted by alex on May 22, 2012 at 01:48 PM PDT #

Nice!

Thanks, very useful. But I agree, it would be very useful that Oracle upload the plugin and the wls-api.jar to a public repository (or create a new one).

Cheers,

Luis

Posted by Luis Rodriguez on May 28, 2013 at 02:57 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today