Hi,
Maven based development and deployment is the choice of most of the developers. WebLogic 12c has worked a lot on that direction.
Oracle Fusion Middleware 12c provides Maven Synchronization plug-in that simplifies the process of setting up repositories and completely eliminates the need to know what patches are installed in a particular environment.
Oracle homes in 12c contain maven directories which contain Maven Project Object Models (POMs) for artifacts provided by Oracle, archetypes for creating projects, and Maven plug-ins provided by Oracle, for executing various build operations.
WebLogic 12c (12.2.1.0) also provides “org.apache.maven_3.2.5” inside it, Which can be used to run Maven in your machines.
export M2_HOME=/PATH/TO/wls1221/oracle_common/modules/org.apache.maven_3.2.5
As part of this example we will see how to install the Oracle Maven Synchronization Plug-In. Few things to remember while going through this article:
Point-1). The default maven local repository location is in the “${HOME}/.m2/repository” directory.
Point-2). For this demo we are using “Oracle WebLogic Server 12.2.1 (12c)” which can be downloaded from: http://www.oracle.com/technetwork/middleware/weblogic/downloads/wls-main-097127.html
Point-3). Even if WebLogic 12c provides it’s own Maven installation, we are using our own Maven Installation. Users can use any maven of their choice.
Setting up Classpath and Maven Environment.
Step-1). First of all we will set the environment variables and the ClassPath by running the “setWLSEnv.sh” script.
$ cd /Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/server/bin $ ./setWLSEnv.sh $ export MW_HOME=/Users/jsensharma/NotBackedUp/Installed/wls1221
If JAVA_HOME is not set then please set that as well in the same command prompt.
Deploy the plugin as following:
Installing Oracle Maven Synchronization plug-in in Local Maven Repo
Step-2). Before we start using the “Oracle Maven Synchronization Plug-In” we will need to install it in our local repository (default: “${HOME}/.m2/repository”) on your computer, or We can also deploy it into our shared internal repository. So Lets run the following command, Make sure to move to the below mentioned directory before running the command mentioned below:
$ cd /Users/jsensharma/NotBackedUp/Installed/wls1221/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1 $ mvn deploy:deploy-file -DpomFile=oracle-maven-sync-12.2.1.pom -Dfile=oracle-maven-sync-12.2.1.jar -Durl=file:///Users/jsensharma/.m2/repository . . . [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom --- Uploading: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.jar Uploaded: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.jar (71 KB at 3509.6 KB/sec) Uploading: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.pom Uploaded: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.pom (9 KB at 8366.2 KB/sec) Downloading: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/maven-metadata.xml Uploading: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/maven-metadata.xml Uploaded: file:///Users/jsensharma/.m2/repository/com/oracle/maven/oracle-maven-sync/maven-metadata.xml (355 B at 346.7 KB/sec) [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.368 s [INFO] Finished at: 2015-11-03T12:35:46+05:30 [INFO] Final Memory: 7M/245M [INFO] ------------------------------------------------------------------------
Here the “/Users/jsensharma/.m2/repository” is my default local maven repository path.
NOTE: Please do not use “~” to define the “-Durl” else you mat encounter issues later.
Observation-1). If you will not define the “-Durl” parameter to define your local repository path here then you may get the following kind of error :
$ mvn deploy:deploy-file -DpomFile=oracle-maven-sync-12.2.1.pom -Dfile=oracle-maven-sync-12.2.1.jar . . . [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.318 s [INFO] Finished at: 2015-11-02T13:59:15+05:30 [INFO] Final Memory: 6M/245M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom: The parameters 'url' for goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file are missing or invalid -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException
Running Oracle Maven Synchronization plug-in
Step-3). Now lets try to run the “Oracle Maven Synchronization plug-in” to see if everything is working fine or not.
. . $ mvn help:describe -Dplugin=com.oracle.maven:oracle-maven-sync:12.2.1-0-0 -Ddetail [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-help-plugin:2.2:describe (default-cli) @ standalone-pom --- [INFO] com.oracle.maven:oracle-maven-sync:12.2.1-0-0 Name: Oracle Maven Synchronization Plugin Description: Maven plugin to load a Maven repository with the contents of the Oracle Home directory Group Id: com.oracle.maven Artifact Id: oracle-maven-sync Version: 12.2.1-0-0 Goal Prefix: oracle-sync This plugin has 2 goals: oracle-sync:help Description: Display help. Implementation: com.oracle.maven.sync.ODMHelp Language: java This mojo doesn't use any parameters. oracle-sync:push Description: Install to the local repository and optionally deploy to a remote repository from the specified oracle home The plugin will use your current Maven settings to determine the path to the local repository and, optionally, a remote deployment repository. For details on how to configure Maven's repository settings, see the Maven settings reference: http://maven.apache.org/settings.html You can specify the parameters on the command line like this: -DserverId=archiva-internal -DdryRun=false -DfailOnError=false To override the localRepository target used by the plugin, you can specify the following option on the command-line: -Dmaven.local.repo=/alternate/path/to/repository To supply an alternate settings.xml for purposes of this operation, use the --settings option. For example: mvn --settings /alternate/path/settings.xml ... ...or in your POM like this: <plugin> <groupId>com.oracle.maven</groupId> <artifactId>oracle-maven-sync</artifactId> <version>12.2.1-0-0</version> <configuration> <oracleHome>/home/mark/Oracle/Middleware</oracleHome> <failOnError>false</failOnError> </configuration> </plugin> Implementation: com.oracle.maven.sync.ODMPushMojo Language: java Available parameters: dryRun (Default: false) User property: dryRun If set to 'true' this goal execution will only log push actions but will not actually make any changes. failOnError (Default: true) User property: failOnError If set to 'true' the plugin will stop and return an error immediately upon the first failure to deploy an artifact. Otherwise, the plugin will log the error and attempt to complete deployment of all other artifacts. localRepository (Default: ${localRepository}) Provide an alternate local repository path to install pushed artifacts to. oracleHome User property: oracleHome Path to the Oracle home. Required. overwriteParent (Default: false) User property: overwriteParent If true, the plugin will overwrite POM artifacts with ancestry to oracle-common if they exist in the target repository. The default value of false will prevent automatic overwrite of customized POM contents. If any such POMs are encountered during plugin execution, an error will be thrown and handled according to the failOnError flag value. To carry over changes, save the existing POMs, run the push goal with overwriteParent=true and manually transfer the changes to the newly pushed POMs. pushDuplicates (Default: false) User property: pushDuplicates Push all duplicate locations. If multiple POMs with different Maven coordinates (GAV) are assigned to the same location path, the plugin will push them all to the destination repository if this flag is true. If the value is false, the push operation will fail. Set failOneError to false if you would like to skip all duplicates except the GAV in the set of duplicates that is encountered first. serverId User property: serverId This is the ID of the server (repository) in your settings.xml file - where you have specified the remote Maven repository and its authentication information. The plugin will only install to the local repository if this parameter is not set. [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.880 s [INFO] Finished at: 2015-11-03T12:43:43+05:30 [INFO] Final Memory: 9M/245M [INFO] ------------------------------------------------------------------------
Observation-2). Just in case if you encounter the following error while running the above command, Then make sure that in the previous step while running the “mvn deploy:deploy-file” you specified the fully qualified PATH for the “-Durl”. (Do not use ~ character while defining the URL)
$ mvn help:describe -Dplugin=com.oracle.maven:oracle-maven-sync:12.2.1-0-0 -Ddetail . . $ mvn help:describe -Dplugin=com.oracle.maven:oracle-maven-sync:12.2.1-0-0 -Ddetail [INFO] Scanning for projects... Downloading: https://repo.maven.apache.org/maven2/com/oracle/maven/maven-metadata.xml [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-help-plugin:2.2:describe (default-cli) @ standalone-pom --- Downloading: https://repo.maven.apache.org/maven2/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.pom [WARNING] The POM for com.oracle.maven:oracle-maven-sync:jar:12.2.1-0-0 is missing, no dependency information available Downloading: https://repo.maven.apache.org/maven2/com/oracle/maven/oracle-maven-sync/12.2.1-0-0/oracle-maven-sync-12.2.1-0-0.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.425 s [INFO] Finished at: 2015-11-03T12:37:40+05:30 [INFO] Final Memory: 10M/245M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-help-plugin:2.2:describe (default-cli) on project standalone-pom: Plugin does not exist: Plugin could not be found, please check its coordinates for typos and ensure the required plugin repositories are defined in the POM [ERROR] com.oracle.maven:oracle-maven-sync:maven-plugin:12.2.1-0-0 [ERROR] [ERROR] from the specified remote repositories: [ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false) [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
NOTE:
It is always better to add the “pluginGroup” inside the “/Users/jsensharma/.m2/settings.xml” (${user.home}/.m2/settings.xml) file as following:
<?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.maven</pluginGroup> </pluginGroups> </settings>
Populating the local repository
Now as the plugin is setup properly hence we will now go ahead and push the WebLogic JARs to the Maven repository. We will achieve it by using the “com.oracle.maven:oracle-maven-sync” command as following:
mvn com.oracle.maven:oracle-maven-sync:12.2.1-0-0:push -Doracle-maven-sync.oracleHome=/Users/jsensharma/NotBackedUp/Installed/wls1221 -DtestingOnly=false
Article is done here. Following part is just to simplify this whole above mentioned lengthy process. So i have written following kind of very simple shell script to automate these steps.
.
.
.
.
.
Simplified Shell Script to Do the Above
I have written the following kind of simple Shell script “weblogic_maven_sync.sh” which will make this whole task easy. Just make sure to set the Variables properly in this script.
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home echo "JAVA_HOME = $JAVA_HOME" echo export M2_HOME=/Users/jsensharma/NotBackedUp/Support_Tools/apache_maven_3.2.3 echo "M2_HOME = $M2_HOME" echo export M2_REPO=/Users/jsensharma/.m2/repository echo "M2_REPO=$M2_REPO" echo export MW_HOME=/Users/jsensharma/NotBackedUp/Installed/wls1221 echo "MW_HOME = $MW_HOME" echo export PATH=$JAVA_HOME/bin:/Users/jsensharma/NotBackedUp/Support_Tools/apache_maven_3.2.3/bin:$PATH: echo "PATH = $PATH" cd $MW_HOME//wlserver/server/bin . ./setWLSEnv.sh cd $MW_HOME/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1 mvn deploy:deploy-file -DpomFile=oracle-maven-sync-12.2.1.pom -Dfile=oracle-maven-sync-12.2.1.jar -Durl=file://${M2_REPO} mvn help:describe -Dplugin=com.oracle.maven:oracle-maven-sync:12.2.1-0-0 -Ddetail mvn com.oracle.maven:oracle-maven-sync:12.2.1-0-0:push -Doracle-maven-sync.oracleHome=$MW_HOME -DtestingOnly=false mvn archetype:crawl -Dcatalog=$HOME/.m2/archetype-catalog.xml
.
.
Known Issue
While running this script or while manually following these steps you might face the following error, which seems to be because of bad “org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.pom” pom , Contact Apache regarding this:
[INFO] ------------------------------------------------------------------------ [INFO] ISSUE DETAILS: [INFO] ------------------------------------------------------------------------ [INFO] POM PARSE ERROR : [INFO] ISSUE #1: /Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/../oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1/~/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.pom Failed to parse POM at "/Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/../oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1/~/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.pom". Repository copy will not be performed for this artifact POM /Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/../oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.2.1/~/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.pom appears to be missing a necessary GAV component: G:A:V:P null:doxia-sink-api:null:jar [INFO] [INFO] [INFO] IMPORTANT NOTE [INFO] This operation may have added/updated archetypes in your repository. [INFO] To update your archetype catalog, you should run: [INFO] 'mvn archetype:crawl -Dcatalog=$HOME/.m2/archetype-catalog.xml'
.
.
Source Code
Please find this script in the MiddlewareMagicDemos Github repo.
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WebLogic/Maven/Maven_Synchronization_Plug-In
.
.
Regards
Jay SenSharma