Maven is: Understanding Apache Maven. – An automated build system +. – A
project management system + ... Maven 3 0 end 2010 object model, a set of ...
1
|
© 2011 Oracle Corporation Proprietary and Confidential
The following is intended to outline our general product direction. It is intended for information purposes only, y and mayy not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
2
|
© 2011 Oracle Corporation Proprietary and Confidential
Using g Maven with WebLogic g Server Jeffrey West, Sr. Principal Product Manager @JeffreyAWest
3
|
© 2011 Oracle Corporation Proprietary and Confidential
Agenda • • • •
Understanding Apache Maven W ki with Working ith W WebLogic bL i S Server ffrom M Maven Advanced Uses of Maven with WebLogic Server Java IDEs and Maven
4
|
© 2011 Oracle Corporation Proprietary and Confidential
Understanding U d t di A Apache h Maven
5
|
© 2011 Oracle Corporation Proprietary and Confidential
What is Maven Understanding Apache Maven • An Apache open source project • Maven is: – – – – – –
An automated build system + A project management system + A library and dependency handling system + A project j d description i i system + A site generation system + … Maven is a project management tool which encompasses a project
• Mature M t – Maven 1.0 2004 – Maven 2.0 2005 – Maven 3.0 3 0 end 2010
object model, a set of standards, a project lifecycle, a dependency object model, a set of standards, a project lifecycle, a dependency management system, and logic for executing plugin goals at defined phases in a lifecycle. When you use Maven, you describe your project using a well‐defined project object model, Maven can then apply cross‐cutting logic from a set of shared (or custom) plugins. Jason Van Zyl Sonatype Jason Van Zyl, Sonatype
6
|
© 2011 Oracle Corporation Proprietary and Confidential
Primary Maven Concepts Understanding Apache Maven • Project Object Model (POM) – A project is the fundamental unit of work in the Maven universe – The POM describes the project, its name/version, type, dependencies, etc. – Portable!
• Convention over Configuration – – – – –
Sensible default behaviours for projects Standard directory layout for project, no configuration necessary, no path settings required Enables automation of build and packaging process Use default directories to locate resources, sources, tests, generate classes, packages Well defined project lifecycle
7
|
© 2011 Oracle Corporation Proprietary and Confidential
Maven Build Lifecycle, Phases and Goals Understanding Apache Maven • Maven 2.0 is based around the central concept of a build lifecycle – The process for building and distributing a particular artifact (project) is clearly defined – Only necessary to learn a small set of commands to build any Maven project, the POM ensures the project is built correctly – default, clean, site
• Build lifecycles f are further f defined f by a set off build phases – A build phase represents a stage in the lifecycle – Executed sequentially to complete the default lifecycle
• Build phase made up of goals – Phases are composed of goals that perform actual tasks – Default goal bindings for standard lifecycle phases – Plugins Pl i contribute t ib t additional dditi l goals l tto project j t 8
|
© 2011 Oracle Corporation Proprietary and Confidential
Maven Default Lifecycle
validate: ensure the validate: ensure the project is correct and all necessary information is available
compile: compile the compile compile the source code of the project
deploy: for final release, copies the final package to the remote repository for sharing with other developers and projects.
install: install the package into the local repository, for use as a dependency in other projects locally
test: test the compiled g source code using a suitable unit testing framework; tests should not require the code be packaged or deployed
package: take the compiled code and compiled code and package it in its distributable format, such as a JAR, WAR, etc.
verify: run checks to verify the package is valid and meets quality criteria
integration‐test: process and deploy the package if necessary into an necessary into an environment where integration tests can be run
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html 9
|
© 2011 Oracle Corporation Proprietary and Confidential
Primary Maven Concepts - Repositories Locating Dependencies and Plugins • A Maven repository holds build artifacts, dependencies and Plugins yp of repositories p • Two strict types – Local – Remote
• Maven automatically looks in remote repositories for missing dependencies/plugins declared in a project • Default PUBLIC repository is Maven Central – http://repo1.maven.org/maven2/ http://repo1 maven org/maven2/
• Additional PUBLIC repositories can be easily defined – Java repository: http://download.java.net/maven/2/
10
|
© 2011 Oracle Corporation Proprietary and Confidential
Primary Maven Concepts - Dependencies Dependency Specification & Management • Maven looks for dependencies using: – Group Id / Artifact Id / Version
• Dependencies can be scoped for: f – Compile / Test / Packaging / Runtime
• Maven automatically manages the download of declared dependencies in a project • Obtained from public and/or corporate repositories p • Stored in local repository for next use
• Declare dependencies, no need to ship libraries with p project j
d d i com.oracle.weblogic weblogic-full tif tId bl i f ll / tif tId 12.1.1 compile ...
11
|
© 2011 Oracle Corporation Proprietary and Confidential
Primary Maven Concepts - Plugins • Plugins perform the work in the Maven ecosystem • Default set of plugins exists from Apache – Bound to lifecycles and phases – Examples: Compile, JAR, WAR, etc.
• Declaratively configured – Similar model to Project dependencies/libraries – Automated download if hosted in public repository – Can be manually installed
• Can C b be executed t d as standalone t d l goals l – mvn wls:deploy
org.apache.maven.plugins maven-compiler-plugin 2.0.2 1.6 1.6 …
• Can be bound to execute for a given lifecycle/phase – mvn deploy
12
|
© 2011 Oracle Corporation Proprietary and Confidential
The Maven Process: End-to-End Input Project pom.xml Local l Repository
Maven Plugins
Maven
Output
Build package
Custom Plugins
13
|
© 2011 Oracle Corporation Proprietary and Confidential
A Sample Maven Web Project for EE6 simple-maven-example 4.0.0 com.oracle.weblogic.examples war 1.0 simple-maven-example plugin org.apache.maven.plugins maven-compiler-plugin 1.6 1.6 g g … Available at http://java.net/projects/weblogic-examples/sources/weblogic-12chttp://java net/projects/weblogic examples/sources/weblogic 12c user-examples/show/jeffrey.west/maven-examples/simple-maven-example
… org.apache.maven.plugins maven-war-plugin 2.1.1 e so / e so false p g javax javaee-api 6.0 provided
14
|
© 2011 Oracle Corporation Proprietary and Confidential
Building the Sample Web Project C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\simple-maven-example>mvn package [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building simple-maven-example [INFO] task-segment: [package] [INFO] -----------------------------------------------------------------------[INFO] [resources:resources {execution: default-resources}] [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\simple-maven-example\src\main\resources [INFO] [compiler:compile {execution: default-compile}] [INFO] Compiling 1 source file to C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\simple-maven-example\target\classes [INFO] [resources:testResources {execution: default-testResources}] [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\simple-maven-example\src\test\resources [INFO] [compiler:testCompile {execution: default-testCompile}] [INFO] No sources to compile [INFO] [surefire:test {execution: default-test}] [INFO] No tests to run. [INFO] [war:war {execution: default-war}] [INFO] Packaging webapp [INFO] Assembling webapp [simple-maven-example] in [C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\simple-maven-example\target\simple-maven-example-1.0] [INFO] Processing war project [INFO] Webapp assembled in [24 msecs] [INFO] Building war: C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\simple-maven-example\target\simple-maven-example-1.0.war [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] -----------------------------------------------------------------------[INFO] Total time: 1 second [INFO] Finished at: Wed Jan 04 16:15:51 PST 2012 [INFO] O Final Memory: 12M/29M / [INFO] ------------------------------------------------------------------------
• Add example of mvn running sample pom.
15
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic W bL i S Server and d Maven
16
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic Server Maven Support Overview • Introduced with WebLogic Server 11g R1 PS3 (10.3.4) supporting Application Deployment operations – Maven Mojo j + WebLogic g Deployer p y + WebLogic g Client – Supported Deployment Lifecycle operations: list-apps, deploy/undeploy, start, stop and update
• WebLogic 12c (12.1.1) provides additional functionality since the 11g release – Installation of Weblogic ZIP Distribution onto a machine where WebLogic has not been installed – WebLogic Domain Creation – Start/Stop WebLogic Servers – Execute WLST Scripts
17
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic 12.1.1 - Maven Integration Update
New New New New New e
• Enable/support/automate the full development lifecycle from Maven l /f ti l supportt • N New M Maven goals/functional – install: automate install from zip file – domain creation: create a simple domain – server lifecycle: start-server, stop-server – wlst: execute inline and external WLST scripts – appc: compile Maven artifacts using appc – deployment: deploy apps to server
WebLogic Domain Development Server Spring Apps Java EE
• Simple and intuitive • Additional WebLogic/FMW enhancements planned 18
|
© 2011 Oracle Corporation Proprietary and Confidential
Using the WebLogic - Maven Plugin • Install WebLogic Maven Plugin into local Maven repository • Configure WebLogic Maven Plugin for use with a project through the POM • Use WebLogic Maven Plugin goals to enact WebLogic installation, domain creation & application deployment operations
19
|
© 2011 Oracle Corporation Proprietary and Confidential
Installing the WebLogic Maven Plugin • Use Maven install:install-file goal to install the wls maven plugin jar library wls-maven-plugin.jar – Must specify name, version and other meta-data to describe and uniquely identify plugin (coordinates) – Can extract and use pom.xml from wls-maven-plugin.jar to automatically supply coordinates – install:install-file install:install file will install the plugin into your local repository
• Alternatively deploy:deploy-file can be used to deploy the plugin to a remote repository 20
|
© 2011 Oracle Corporation Proprietary and Confidential
Installing the WebLogic Maven Plugin C:\wls1211\wlserver_12.1\server\lib>jar xvf wls-maven-plugin.jar META-INF/maven/com.oracle.weblogic/wls-maven-plugin/pom.xml inflated: META-INF/maven/com.oracle.weblogic/wls-maven-plugin/pom.xml C:\wls1211\wlserver 12 1\server\lib>mvn install:install-file C:\wls1211\wlserver_12.1\server\lib>mvn install:install file -Dfile=wls-maven-plugin.jar Dfile=wls maven plugin jar -DpomFile=METADpomFile=META INF/maven/com.oracle.weblogic/wls-maven-plugin/pom.xml [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'install'. [INFO] -----------------------------------------------------------------------[INFO] Building WebLogic Server Maven Plugin [INFO] task-segment: [install:install-file] (aggregator-style) [INFO] -----------------------------------------------------------------------[INFO] [install:install-file {execution: default-cli}] [INFO] Installing C:\wls1211\wlserver_12.1\server\lib\wls-maven-plugin.jar to C:\Data\tools\maven-repository\com\oracle\weblogic\wls-mavenplugin\12.1.1.0\wls-maven-plugin-12.1.1.0.jar [INFO] Installing C:\wls1211\wlserver C:\wls1211\wlserver_12.1\server\lib\pom.xml 12.1\server\lib\pom.xml to C:\Data\tools\maven-repository\com\oracle\weblogic\wls-maven-plugin\12.1.1. C:\Data\tools\maven repository\com\oracle\weblogic\wls maven plugin\12.1.1. 0\wls-maven-plugin-12.1.1.0.pom [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
21
|
© 2011 Oracle Corporation Proprietary and Confidential
Configure WebLogic Maven Plugin in Project Maven pom.xml pom xml Configuration •
WebLogic Maven Plugin needs to be configured as a plugin for a project to enable it to be used
•
Specify plugin coordinates, target server configuration and Middleware Home com.oracle.weblogic g p g g p wls-maven-plugin 12.1.1.0 c:\wls1211 t3://127.0.0.1 weblogic welcome1
22
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic W bL i M Maven Pl Plugin i Deployment Lifecycle Demo
23
|
© 2011 Oracle Corporation Proprietary and Confidential
Executing WebLogic Maven Plugin Goals • Invoke I k wls-maven-plugin l l i goals l di directly tl ffrom mvn command d liline C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-deployment-example>mvn wls:list-apps [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building weblogic-deployment-example [INFO] task-segment: [wls:list-apps] (aggregator-style) [INFO] -----------------------------------------------------------------------[INFO] [wls:list-apps {execution: default-cli}] [INFO] ++====================================================================++ [INFO] ++ wls-maven-plugin: list-apps ++ [INFO] ++====================================================================++ ++ ++ weblogic.Deployer invoked with options: -noexit -adminurl t3://127.0.0.1:7001 -user weblogic -listapps test-project simple-maven-example-1.0 Number of Applications Found : 2 [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] -----------------------------------------------------------------------[INFO] Total time: 2 seconds [INFO] Finished at: Wed Jan 04 16:44:24 PST 2012 [INFO] Final Memory: 9M/22M [INFO] -----------------------------------------------------------------------C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-deployment-example> g p j y p g p y p
24
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic Maven Plugin: Deploy $ mvn wls:deploy -Dname=weblogic-deployment-example-1.0 -Dsource=target/weblogic-deployment-example-1.0.war [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building weblogic-deployment-example [INFO] task-segment: [wls:deploy] (aggregator-style) [INFO] -----------------------------------------------------------------------[INFO] [wls:deploy {execution: default-cli}] [INFO] ++====================================================================++ [INFO] ++ wls-maven-plugin: deploy ++ [[INFO]] ++====================================================================++ weblogic.Deployer invoked with options: -noexit -adminurl t3://127.0.0.1:7001 -user weblogic -deploy -name weblogic-deployment-example-1.0 -source target/weblogicdeployment-example-1.0.war Task 2 initiated: [Deployer:149026]deploy application weblogic-deployment-example-1.0 on AdminServer. Task 2 completed: [Deployer:149026]deploy application weblogic-deployment-example-1.0 on AdminServer. Target state: deploy completed on Server AdminServer [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
25
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic Maven Plugin: Redeploy $ mvn wls:redeploy -Dname=weblogic-deployment-example-1.0 -Dsource=target/weblogic-deployment-example-1.0.war [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building weblogic-deployment-example [INFO] task-segment: [wls:redeploy] (aggregator-style) [INFO] -----------------------------------------------------------------------[INFO] [wls:redeploy [ l d l {execution: { ti default-cli}] d f lt li}] [INFO] ++====================================================================++ [INFO] ++ wls-maven-plugin: redeploy ++ [INFO] ++====================================================================++ weblogic.Deployer invoked with options: -noexit -adminurl t3://127.0.0.1:7001 -user weblogic -redeploy -name weblogic-deployment-example-1.0 -source target/weblogicdeployment-example-1.0.war Task 3 initiated: [Deployer:149026]deploy application weblogic-deployment-example-1.0 on AdminServer. Task 3 completed: [Deployer:149026]deploy application weblogic-deployment-example-1.0 on AdminServer. Target state: redeploy completed on Server AdminServer
• Redeploy
[INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] -----------------------------------------------------------------------[INFO] Total time: 2 seconds [INFO] Finished at: Wed Jan 04 16:52:46 PST 2012 [INFO] Final Memory: 9M/22M [INFO] ------------------------------------------------------------------------
26
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic Maven Plugin: Undeploy $ mvn wls:undeploy -Dname=simple-maven-example-1.0 [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building weblogic-deployment-example [INFO] task-segment: [wls:undeploy] (aggregator-style) [INFO] -----------------------------------------------------------------------[INFO] [wls:undeploy {execution: default-cli}] [INFO] ++====================================================================++ [INFO] ++ wls-maven-plugin: undeploy ++ [INFO] ++====================================================================++ weblogic.Deployer invoked with options: -noexit -adminurl t3://127.0.0.1:7001 -user weblogic -undeploy -name simple-maven-example-1.0 Task 1 initiated: [Deployer:149026]remove application simple-maven-example-1.0 on AdminServer. Task 1 completed: [Deployer:149026]remove application simple-maven-example-1.0 on AdminServer. Target state: undeploy completed on Server AdminServer [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] -----------------------------------------------------------------------[INFO] Total time: 2 seconds [INFO] Finished at: Wed Jan 04 16:47:20 PST 2012 [INFO] Final Memory: 9M/22M [INFO] ------------------------------------------------------------------------
27
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic W bL i M Maven Pl Plugin i Provisioning Demo
28
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic Zip Distribution • WebLogic is now available in ZIP format at only 164MB! • The WebLogic Zip Distribution can be downloaded from OTN
29
|
© 2011 Oracle Corporation Proprietary and Confidential
Installing the WebLogic Zip Distribution in your Local Repository • The WebLogic g ZIP Distribution must be available in yyour local repository or a remote repository • Install the WebLogic ZIP Distribution into your local repository using the Maven install:install-file goal $ mvn install:install-file -Dfile=wls1211_dev.zip -DgroupId=com.oracle.weblogic -DartifactId=wls-dev -Dpackaging=zip Dversion=12.1.1.0
30
|
© 2011 Oracle Corporation Proprietary and Confidential
Configuring the WebLogic Plugin Install goal com oracle weblogic com.oracle.weblogic wls-maven-plugin 12.1.1.0 t3://127 0 0 1:7001 t3://127.0.0.1:7001 weblogic welcome1 ${project.build.directory}/domain
com oracle weblogic:wls-dev:zip:12 1 1 0 com.oracle.weblogic:wls-dev:zip:12.1.1.0
31
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic Maven Plugin: Install g p j y p g p g p C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example>mvn wls:install [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building weblogic-provisioning-example [INFO] task-segment: [wls:install] (aggregator-style) [INFO] -----------------------------------------------------------------------[INFO] [wls:install {execution: default-cli}] [INFO] ++====================================================================++ [INFO] ++ wls-maven-plugin: install ++ [INFO] ++====================================================================++ [INFO] Installing com.oracle.weblogic:wls-dev:zip:12.1.1.0 into: C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example\Oracle\Software [INFO] Installing the product, this may take some time. [INFO] Executing: [cmd:[C:\\Windows\\system32\\cmd.exe, /c, configure.cmd]] [INFO] Process being executed, waiting for completion. [INFO] [exec] ************************************************** [INFO] [exec] WebLogic Server 12c (12.1.1.0) Zip Configuration [INFO] [exec] [INFO] [exec] MW_HOME: C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example\Oracle\Software [INFO] [exec] JAVA_HOME: C:\wls1035\jdk160_24 [INFO] [exec] ************************************************** [INFO] [exec] [INFO] [exec] 771 jar files are being unpacked. [INFO] [exec] Please wait, title bar will show progress ... [INFO] [exec] [INFO] [exec] "ACLs are being setup for C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example\Oracle\Software Please wait..." [INFO] [exec] [INFO] [exec] CLASSPATH=“…" [INFO] [exec] [INFO] [exec] PATH=“…." [INFO] [exec] [INFO] [exec] Your environment has been set. [INFO] [exec] [INFO] [exec] BUILD SUCCESSFUL [INFO] [exec] Total time: 0 seconds [INFO] [configure script] exit code: 0 [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] -----------------------------------------------------------------------32
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic Maven Plugin: Create Domain C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example>mvn wls:create-domain [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building weblogic-provisioning-example [INFO] task-segment: task segment [[wls:create-domain] ls create domain] (aggregator-style) (aggregator st le) [INFO] -----------------------------------------------------------------------[INFO] [wls:create-domain {execution: default-cli}] [INFO] ++====================================================================++ [INFO] ++ wls-maven-plugin: create-domain ++ [INFO] ++====================================================================++ [INFO] Domain creation script: readTemplate(r'C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioningexample\Oracle\Software\wlserver\common\templates\domains\wls.jar') cd('/Security/base_domain/User/weblogic') set('Name', 'weblogic') set('Password' set( Password , '***')) writeDomain(r'C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example\target\domain') [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
33
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic Maven Plugin: Start Server C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example>mvn wls:start-server [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building weblogic-provisioning-example [INFO] task-segment: task segment [[wls:start-server] ls start ser er] (aggregator (aggregator-style) st le) [INFO] -----------------------------------------------------------------------[INFO] [wls:start-server {execution: default-cli}] [INFO] ++====================================================================++ [INFO] ++ wls-maven-plugin: start-server ++ [INFO] ++====================================================================++ .[INFO] Starting server in domain: C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example\target\domain [INFO] Check stdout file for details: C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example\target\domain\ server-5223679401799187816.out [INFO] Process being executed, waiting for completion. ... [INFO] Server started successful [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
34
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic Maven Plugin: WLST p g p g p py C:\maven-examples\weblogic-provisioning-example>mvn wls:wlst -DfileName=src\main\wlst\createDatasource.py [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building weblogic-provisioning-example [INFO] task-segment: [wls:wlst] (aggregator-style) [INFO] -----------------------------------------------------------------------[INFO] [wls:wlst {execution: default-cli}] [INFO] ++====================================================================++ [[INFO]] ++ wls-maven-plugin: p g wlst ++ [INFO] ++====================================================================++ Connecting to t3://127.0.0.1:7001 with userid weblogic ... Successfully connected to Admin Server 'AdminServer' that belongs to domain 'domain'. Warning: An insecure protocol was used to connect to the server. To ensure on-the-wire security, the SSL port or Admin port should be used instead. Location changed to edit tree. This is a writable tree with DomainMBean as the root. To make changes you will need to start an edit session via startEdit(). For more help, use help(edit) Starting an edit session ... please be sure to save and activate yyour Started edit session, p changes once you are done. Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. Activation completed [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [[INFO]] -----------------------------------------------------------------------[INFO] Total time: 7 seconds [INFO] Finished at: Sat Jan 14 17:51:08 PST 2012 [INFO] Final Memory: 19M/45M [INFO] -----------------------------------------------------------------------35
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic Maven Plugin: Stop Server C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example>mvn wls:start-server [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building weblogic-provisioning-example [INFO] task-segment: task segment [[wls:start-server] ls start ser er] (aggregator (aggregator-style) st le) [INFO] -----------------------------------------------------------------------[INFO] [wls:start-server {execution: default-cli}] [INFO] ++====================================================================++ [INFO] ++ wls-maven-plugin: start-server ++ [INFO] ++====================================================================++ .[INFO] Starting server in domain: C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example\target\domain [INFO] Check stdout file for details: C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-provisioning-example\target\domain\ server-5223679401799187816.out [INFO] Process being executed, waiting for completion. ... [INFO] Server started successful [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
36
|
© 2011 Oracle Corporation Proprietary and Confidential
Advanced Ad dU Uses off WebLogic Server Maven Plugin
37
|
© 2011 Oracle Corporation Proprietary and Confidential
Advanced Uses of WebLogic Maven Plugin • Automating deployment parameters using Maven properties • Binding the WebLogic Plugin to Maven execution phases for automating Deployment & Provisioning operations • Using Maven Profiles for multiple deployment targets • Simplifying Configuration with Inheritance • Integration with Continuous Integration servers 38
|
© 2011 Oracle Corporation Proprietary and Confidential
Automating Deployment Parameters • Can make use Maven implicit properties to automatically set the parameter values based on project details com.oracle.weblogic wls-maven-plugin 12.1.1.0 c:\wls1211 t3://127.0.0.1:7001 weblogic welcome1 ${project.build.finalName} ${project.build.directory}/${project.build.finalName}.${project.packaging} 39
|
© 2011 Oracle Corporation Proprietary and Confidential
Automating Deployment Parameters $ mvn wls:deploy [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building weblogic-deployment-example [INFO] task-segment: [wls:redeploy] (aggregator-style) [INFO] -----------------------------------------------------------------------[INFO] [wls:redeploy {execution: default-cli}] [INFO] ++====================================================================++ [INFO] ++ wls-maven-plugin: redeploy ++ [INFO] ++====================================================================++ weblogic.Deployer invoked with options: -noexit -adminurl t3://127.0.0.1:7001 -user weblogic -redeploy -name weblogic-deployment-example1.0 -source C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-deployment-example\target/weblogic-deploymentexample-1.0.war p y ] p y application pp weblogic-deployment-example-1.0 g p y p on AdminServer. Task 5 initiated: [[Deployer:149026]deploy Task 5 completed: [Deployer:149026]deploy application weblogic-deployment-example-1.0 on AdminServer. Target state: redeploy completed on Server AdminServer [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
40
|
© 2011 Oracle Corporation Proprietary and Confidential
Associating WebLogic tasks w/ Maven Phases • Maven plugin goals can be bound to a Maven phase to execute during that phase Useful for automating deployment of target application to a server • Useful for automating deployment of target application to a server for testing as part of Maven lifecycle • Use the section of the tag to specify the t target phase and the goal(s) to execute t h d th l( ) t t Pre‐Integration‐Test: install, create‐domain, start‐server, deploy Integration‐Test: Post‐Integration‐Test: undeploy, stop‐server, clean g p y, p , 41
|
© 2011 Oracle Corporation Proprietary and Confidential
Plugin Phase/G Goal Binding
Automatic Execution of Deployment Goals deploy pre-integration-test deploy ${project.build.directory}/${project.build.finalName}.${project.packaging} ${project.build.finalName} undeploy post-integration-test undeploy l d l / l ${project.build.finalName}
42
|
© 2011 Oracle Corporation Proprietary and Confidential
Mav ven Fails safe IT P Plugin
Automated Integration Testing with Deployment ------------------------------------------------------TESTS ------------------------------------------------------Running servlets.AddingServletIT Strings Match (PASS): 1+2=3 | 1+2=3 Strings do not Match (PASS): 1+2=3 1+2 3 | 1+2 1+2=4 4 Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.077 sec Results : Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! [INFO] [failsafe:verify {execution: default}] [INFO] Failsafe report directory: C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-integration-test-example\target\failsafe-reports [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! [INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL [INFO] -----------------------------------------------------------------------[INFO] Total time: 3 seconds [INFO] Finished at: Fri Jan 06 12:03:21 PST 2012 [INFO] Final Memory: 15M/37M [INFO] -----------------------------------------------------------------------C:\weblogic-12c-user-examples\jeffrey.west\maven-examples\weblogic-integration-test-example>
43
|
© 2011 Oracle Corporation Proprietary and Confidential
U Undeploy
Integra ation Tes st
D Deploy
Automatic Execution of Deployment Goals $ mvn verifyy [INFO] Scanning for projects... [INFO] -----------------------------------------------------------------------[INFO] Building demo-wls-maven [INFO] task-segment: [verify] [INFO] -----------------------------------------------------------------------[INFO] [war:war {execution: default-war}] [INFO] Packaging webapp [INFO] Assembling webapp[demo-wls-maven] in [/Users/sbutton/Projects/Java/demo-wls-maven/target/demo-wls-maven] [INFO] Processing war project [INFO] Copying webapp resources[/Users/sbutton/Projects/Java/demo-wls-maven/src/main/webapp] [INFO] Building war: /Users/sbutton/Projects/Java/demo-wls-maven/target/demo-wls-maven.war [INFO] [null:deploy {execution: deploy}] weblogic Deployer invoked with options: -noexit weblogic.Deployer noexit -adminurl adminurl t3://localhost:7001 -user user weblogic -deploy deploy -name name demo demo-wls-maven wls maven -source source /Users/sbutton/Projects/Java/demo-wls-maven/target/demo-wls-maven.war Task 24 initiated: [Deployer:149026]deploy application demo-wls-maven on myserver. Task 24 completed: [Deployer:149026]deploy application demo-wls-maven on myserver. Target state: deploy completed on Server myserver [INFO] [null:undeploy {execution: undeploy}] weblogic.Deployer invoked with options: -noexit -adminurl t3://localhost:7001 -user weblogic -undeploy -name demo-wls-maven Task 25 initiated: [Deployer:149026]remove application demo-wls-maven on myserver. Task 25 completed: p [[Deployer:149026]remove p y ] application pp demo-wls-maven on myserver. y Target state: undeploy completed on Server myserver
44
|
© 2011 Oracle Corporation Proprietary and Confidential
Using Maven Profiles for Multiple sets of Environment Parameters p y deploy-local < d i l>${ bl i D l ${weblogic.Deployer.adminurl} d i l} ${weblogic.Deployer.user} t3://127.0.0.1:7001 ${weblogic.Deployer.password} weblogic ${weblogic.Deployer.application.targets} welcome1 true AdminServer p p true ${project.build.directory}/${project.build.finalName}.${project.packaging} ${project.artifactId} deploy-dev t3://10.0.0.1:7001 weblogic welcome1 AdminServer
$ mvn wls:deploy –P deploy-local $ mvn wls:deploy –P deploy-dev
45
|
© 2011 Oracle Corporation Proprietary and Confidential
Simplifying Configuration with Inheritance common common‐ deployable
Holds common dependency & plugin configuration Examples: JDK 1.6, EE6 API’s
Holds common dependency and plugin configuration for projects that are deployable to WebLogic
web‐ project‐1
Holds Web Project, no additional configuration required to deploy to WebLogic
web‐ project‐2
Holds Web Project, no additional configuration required to deploy to WebLogic
46
|
© 2011 Oracle Corporation Proprietary and Confidential
WebLogic, W bL i M Maven & Continuous Integration
47
|
© 2011 Oracle Corporation Proprietary and Confidential
Integration with Continuous Integration Servers
CI Server Code Repository p y
Compile & Package
WebLogic S Server 48
|
© 2011 Oracle Corporation Proprietary and Confidential
Several CI Servers are Free and Open Source
H d Hudson
49
|
© 2011 Oracle Corporation Proprietary and Confidential
Integration with Continuous Integration Servers Hudson CI Server • Dashboard displays status of all jobs • Builds automatically triggered from SCM changes • JJobs b can b be created t d di directly tl from a Maven project • Maven “install” lifecycle used • Executes build, package, test, integration-test phases
50
|
© 2011 Oracle Corporation Proprietary and Confidential
Integration with Continuous Integration Servers • Automatic deployment to WLS on SCM change • Integration g tests run against application on WLS • Results reported as build status 51
|
© 2011 Oracle Corporation Proprietary and Confidential
Integration with Continuous Integration Servers Tests executed against application deployed on WLS @Test public void calculatorServletError() throws Exception { int p1 = 1; int p2 = 2; int res = 0; String test = String.format("http://localhost:7001/demo-wlsmaven/CalculatorServlet?p1=%s&p2=%s", p1, p2); String expect = String.format("%s+%s=%s", p1, p2, res); final WebClient webClient = new WebClient(); final HtmlPage page = webClient.getPage(test); final String pageAsText = page.asText(); assertTrue(pageAsText.contains(expect)); }
52
|
© 2011 Oracle Corporation Proprietary and Confidential
J Java IDE and IDEs dM Maven
53
|
© 2011 Oracle Corporation Proprietary and Confidential
IDE Maven Support • Most current IDE’s support Maven • Common C F Features t – Materialize projects from Maven POM – Dependency Integration with Compile / Test / Run Classpath – Maven Repository Browsing – Multi-Module Maven Project Support – Form-based POM Editor – Dependency Graph 54
|
© 2011 Oracle Corporation Proprietary and Confidential
Eclipse, OEPE and Maven Maven IDE Support http://m2eclipse.sonatype.org/sites/m2e
• Maven support in Eclipse provided by the open-source M2Eclipse plugin l i ffrom Sonatype S t • Install from M2Eclipse update site
55
|
© 2011 Oracle Corporation Proprietary and Confidential
Eclipse, OEPE and Maven – M2Eclipse Plugin Features • Creating and importing Maven projects • Dependency management and integration with the Eclipse classpath • Automatic dependency downloads and updates • Artifact Javadoc and source resolution • Creating projects with Maven Archetypes • Browsing and searching remote Maven repositories • POM management with automatic update to dependency list g a project j from a Maven POM • Materializing • Adapting nested multi-module Maven projects to the Eclipse IDE • Form-based and text-based POM Editor • GUI Presentation of Dependency Tree and Resolved Dependencies Source: http://m2eclipse.sonatype.org/index.html 56
|
© 2011 Oracle Corporation Proprietary and Confidential
Eclipse, OEPE and Maven WebLogic Maven Plugin • Use wls-maven-plugin as per any other Maven project • Add/ Add/view i plugin l i settings i using POM editor • Execute Maven builds call wls-maven-plugin goals 57
|
© 2011 Oracle Corporation Proprietary and Confidential
NetBeans and Maven • NetBeans 6.7+ provides native support pp for Maven 2/3 • Create/Import Maven project • Manage dependencies • Dependency graph viewer • Run/Test projects • Maven M repository it browser b • Can also push a Maven job directly to a Hudson CI server as build jjob 58
|
© 2011 Oracle Corporation Proprietary and Confidential
Oracle O l S Software ft & Public P bli Maven Repositories
59
|
© 2011 Oracle Corporation Proprietary and Confidential
A Note on Licensing Oracle Software & Public Maven Repositories • Oracle Software has a license associated with it • In order to download the software from oracle.com oracle com you must accept the license agreement • Public Maven Repo’s don’t enforce license acceptance • Options: – Use a ‘System’ Dependency – Deploy D l O Oracle l D Dependencies d i tto a shared h d repository it b behind hi d your fifirewallll – Install Oracle JAR’s into your local repository
60
|
© 2011 Oracle Corporation Proprietary and Confidential
System-Scoped Dependencies Managing Oracle Maven Dependencies • Refer to files on a locally accessible filesystem • Can be defined in a Parent POM file and reused by child projects • Middleware Home must be the same path on all machines or property files must be used com.oracle.weblogic weblogic-spring artifactId weblogic spring /artifactId 12.1.1.0 system ${middleware.home}\wlserver_12.1\server\lib\weblogic-spring.jar
61
|
© 2011 Oracle Corporation Proprietary and Confidential
Manually Installed Dependencies Managing Oracle Maven Dependencies
• Install to your Local repository using the install:install-file goal • Development De elopment teams m must st coordinate Gro Group p and Artifact ID’s mvn install:install install:install-file file -DgroupId=com DgroupId com.oracle.weblogic oracle weblogic -DartifactId=weblogic-spring DartifactId weblogic spring -Dversion=12 Dversion 12.1.1.0 110 -Dpackaging=jar -Dfile=/wls1211/wlserver_12.1/server/lib/weblogic-spring.jar
com.oracle.weblogic weblogic-spring 12.1.1.0
62
|
© 2011 Oracle Corporation Proprietary and Confidential
Private Repositories Managing Oracle Maven Dependencies • Create your own Maven Repository behind your corporate firewall using a tool like Apache Archiva • Install Oracle dependencies using deploy:deploy-file • Configure your private repository in your POM files • Suggested approach for larger teams mvn deploy:deploy-file -Durl=[url] -DrepositoryId=[id] -DgroupId=com.oracle.weblogic -DartifactId=weblogic-spring Dversion=12.1.1.0 -Dpackaging=jar -Dfile=/wls1211/wlserver_12.1/server/lib/weblogic-spring.jar
com.oracle.weblogic weblogic-spring 12.1.1.0 63
|
© 2011 Oracle Corporation Proprietary and Confidential
Summary • Maven is a popular open source project lifecycle and build system that provides a very rich and dynamic set of features to help development teams • Maven support introduced in WebLogic Server 11g R1 (10.3.4) and enhanced in 12c (12.1.1) • WebLogic Maven Plugin can install the WebLogic Binaries, Create Domains, Manage Server Lifecycle and Execute deployment operations against a target WebLogic Server instance • Target server deployment operations can be seamlessly incorporated into the Maven lifecycle • Maven has good support in the common Java IDEs
64
|
© 2011 Oracle Corporation Proprietary and Confidential
Code Examples WebLogic Examples on Java.net Java net
• Code examples for Maven-WebLogic can be found here: – http://java http://java.net/projects/weblogic-examples/sources/weblogic-12cnet/projects/weblogic examples/sources/weblogic 12c user-examples/show – jeffrey.west / maven-examples
• You can also submit your own examples if you join the project!
65
|
© 2011 Oracle Corporation Proprietary and Confidential
Join the WebLogic Community O l Oracle.com/weblogic / bl i Twitter twitter.com/oracleweblogic twitter com/oracleweblogic Facebook facebook.com/oracleweblogic Oracle’s WebLogic blog blogs.oracle.com/weblogicserver Youtube Y t b Youtube.com/oracleweblogic Developer Webcast Series oracle.com/goto/weblogicdevcast l / / bl d 66
|
© 2011 Oracle Corporation Proprietary and Confidential