Sunday, May 28, 2017

Apache Maven and SOA 11g. Preparing Environment.

Good time of the day, It's time to resume the story of the happy marriage between SOA Studio 11g and Apache Maven.  This post will guide you trough environment configuration. During the process we will go through:

  • JDeveloper 11g extension configuration 
  • WebLogic Maven plugin configuration
  • Plugin and libraries installation. 
  • Configure External tools.
The actual configuration will take much less time than you would read this document because I have prepared scripts for you.  And good news it's lifetime configuration (for your workstation of course). Although, I presume that you have:
  • Oracle SOA Studio 11g (11.1.1.7.0)  installed and configured;
  • Your workstation has Internet access, or at least you have access to extensions and maven repository replicas. 
  • You know you Oracle Fusion Middleware directory name. If you don't it's location where you see folders similar to the screenshot below: 

Configure JDeveloper Extensions

You may have Apache Maven installed on your workstation, especially if you work under Linux and of course, it's the latest greatest one. However we should always keep in mind compatibility, so Let's use Maven, which will work for sure with our JDK and JDeveloper. If you'd make such thing and it will work with the latest maven releases, please let me know. 
Okay, Maven plugin installation is dull:
  1.  Start Oracle JDeveloper
  2. From the main menu select Help -> “Check For Updates …”
  3. In the Source list check  "Open Source and Partners Extensions" 
  4.  Locate and select 2 extensions with the name like  “Developer Preview: Maven*”
  5. Complete installation and restart IDE. 
To validate the installation 
  1.   Open command line window or shell terminal on the Linux box.
  2.  Go to your JDeveloper installation home  (in my case it’s C:\Oracle\Middleware\JDeveloper)
    C> cd \Oracle\Middleware\JDeveloper
  3. Check if you have your maven 2.1 installed and configured:
C:\Oracle\Middleware\jdeveloper>apache-maven-2.1.0\bin\mvn –version
Apache Maven 2.1.0 (r755702; 2009-03-18 15:10:27-0400)
Java version: 1.7.0_55
Java home: C:\Oracle\sqldeveloper.40\jdk\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"

Before you continue with the further configuration, let's check what JRE/JDK is available in your system by default. For me, it's Java 7 and it will not work for SOA projects because default JDK for 11.1.1.7 is JDK 1.6.  You can fix it with the environment variable JAVA_HOME which will point to the JDK from the Oracle Middleware. I prefer change JDK only for the maven script.  Steps are easy:

  1. Go to Maven extension bin folder 
  2.  Copy mvn or mvn.bat file to mvn6 or mvn6.bat (OS-depended)
  3.  Open mvn6 for edit and  add the new line in position 35 or 34:
    JAVA_HOME=C:\Oracle\Middleware\jdk160_24
  4. Save file and retest
    C:>cd \Oracle\Middleware\jdeveloper\apache-maven-2.1.0\bin\
    C>mvn6 --version
    Apache Maven 2.1.0 (r755702; 2009-03-18 15:10:27-0400)
    Java version: 1.6.0_24
    Java home: C:\Oracle\Middleware\jdk160_24\jre
    Default locale: en_US, platform encoding: Cp1252
    OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
    C:\Oracle\Middleware\jdeveloper>
Worth to notice, that you may create $HOME/.mavenrc for Mac/Linux or %USERPROFILE%\mavenrc_pre.bat for Window and keep all Maven related environment configuration settings there.

Configure WebLogic plugin

For the start, we prepare plugin archive and classes required for the plugin installation. 
Let's start from the session environment configuration:
  1. Set environment variables:

    C:>SET FMW_HOME=C:\Oracle\Middleware
    C:>SET ORACLE_HOME=%FMW_HOME%\JDeveloper
    C:>SET MVN_HOME=%ORACLE_HOME%\apache-maven-2.1.0
    C:>SET WLS_HOME=%FMW_HOME%\wlserver_10.3
    C:>SET JAVA_HOME=%FMW_HOME%\jdk160_24
  2. Generate full client library:
    C:>cd %WLS_HOME%\server\lib\
    C:>%JAVA_HOME%\bin\java -jar %WLS_HOME%\server\lib\wljarbuilder.jar -profile wlfullclient
  3. Generate Maven plugin library:
                C:>%JAVA_HOME%\bin\java -jar %WLS_HOME%\server\lib\wljarbuilder.jar –profile weblogic-maven-plugin
  4. Extract plugin model user jar tool or archiver program like 7-zip. Additional details could be found in Oracle Documentation.  Or just use wls-pom.xml from the script repository. 
  5. Install libraries required by the plugin at runtime:

    C:>%MVN_HOME%\bin\mvn install:install-file -DgroupId=com.oracle.cryptoj -DartifactId=cryptoj -Dversion=1.0 -Dpackaging=jar -Dfile=%FMW_HOME%\modules\cryptoj.jar -DgeneratePom=true
    C:>%MVN_HOME%\bin\mvn install:install-file -DgroupId=weblogic -DartifactId=weblogic -Dversion=10.3.6 -Dpackaging=jar -Dfile=%WLS_HOME%\server\lib\weblogic.jar
    C:>%MVN_HOME%\bin\mvn install:install-file -DgroupId=weblogic -DartifactId=weblogic -Dversion=10.3.6  -Dpackaging=jar -Dfile=%WLS_HOME%\server\lib\wlfullclient.jar 
    C:>%MVN_HOME%\bin\mvn install:install-file -DgroupId=weblogic -DartifactId=webservices -Dversion=10.3.6  -Dpackaging=jar -Dfile=%WLS_HOME%\server\lib\webservices.jar

  6. Install WebLogic Maven plugin:

    C:>%MVN_HOME%\bin\mvn install:install-file -Dfile=weblogic-maven-plugin.jar -DpomFile=pom.xml
  7. Test plugin configuration:
    C:>%MVN_HOME%\bin\mvn  weblogic:help
Successful output should looks like this one:

Configure External Tools. 

JDeveloper Maven extension adds project and application support however, it's bound rather to the project that application. So, I normally create 3 additional external tools, all of them call maven with 3 major goals: clean, build and install. I'll guide you through the first one, Create the rest on your own. 

  1. From the JDeveloper main menu select Tools/External Tools… 
  2. Click on the “New …” button
  3. Select External Program as a tool type
  4. Specify program parameters as below. Don't forget to use substitutions, it will make your tools project unaware.
  5. Click Next button.
  6. Give the caption for the command, ToolTip text and select icon for the command to show.  Maven icons could be found in  ${ide.oracle.dir}\jdev\extensions\oracle.jdeveloper.maven.jar, as on the screenshot below.
  7. Click Next. 
  8. I prefer to have all Maven tools in one click distance and add buttons to the Main Toolbar. Also, don't forget to mark "Save All" as before starts action. 
  9. Save External tool and repeat steps 1-9 for the other Maven goals. 
At this point, you have configured and integrated:

  • SOA Studio 11g with the Maven extension;
  • Apache Maven 2.1 installed with JDeveloper. 
  • Configured local repository with the Weblogic plugin
  • Universal external tools to clean, package and install applications.
Next time I'll show you how to build Web applications with Apache Maven. 

So long and thanks for all the fish! 

Post a Comment