Jumpstarting Development on the Cloud – Part 2 : Packaging and Build

 

Introduction

The Oracle Developer Cloud Service (DevCS) is a cloud-based software development Platform as a Service (PaaS) and a hosted environment for your application development infrastructure. It provides an open source standards-based solution to develop, collaborate on, and deploy applications within Oracle Cloud. Some of the core features offered by DevCS include a hosted GIT repository, a Maven repository, Issue Tracking capabilities, a Hudson Continuous Integration (CI) server, Wiki collaboration, code-review, roles and responsibilities separation, and many more. The complete list of features is available here.

While the documentation of all these features is available at http://docs.oracle.com/cloud/latest/devcs_common/index.html , in this blog we’ll concentrate on the Maven aspect of DevCS. Specifically, we’ll describe how one can :

Developer Cloud Service lets you create a number of ‘projects’. With each project, an instance of Hudson CI Server, a GIT repository, a Maven Repository and a Wiki server are allotted. Below is a snapshot of the DevCS project home page:

The environment specific data has been redacted from the images in this blog.


DevCS-default

It can be seen above that there are two git repositories attached to the project. DevCS allows a number of GIT repositories, both hosted and external, to be attached to a project. This provides flexibility to the Project Management team within your organization to logically separate projects as needed. The GIT Repositories can be managed via the Admin tab, where the result is shown below :

Populating the Maven Repository

In this section we will go through the steps to populate the DevCS Maven repository with the Weblogic 12.1.2 libraries, although the steps are valid for any version of Weblogic 12c.

Since the Weblogic libraries are Oracle copyrighted, care must be taken to ensure the libraries aren’t publicly accessible. Since a DevCS Maven repository is protected via HTTP Authentication, it’s OK to upload the libraries there.

The entire process can be divided into three main steps :

  1. a. Setting up Maven on a local machine.
  2. b. Installing Weblogic binaries on the local machine.
  3. c. Pushing the local binaries to the remote Maven repository.

Before starting the upload, it is important to consider the network latency and upload speed to ensure the upload happens as quickly as possible.
Also, if a large number of libraries are to be uploaded, it is worth considering a VNC type session, so that session interruptions do not interfere with the upload.

a) Setting up Maven on the local Machine

    1. i. Download and install the apache-maven-3.x.x (we used 3.0.5) on the local Machine (say a linux VM).

 

  1. ii. Open MVN_HOME/conf/settings.xml and make the following changes.
      1. 1) Under the ‘proxies’ section, specify the appropriate proxy, as given below:
      2. <proxies>   
            <proxy>
              <active>true</active>
              <protocol>http</protocol>
              <host>PROXY_URL</host>
              <port>80</port>
              <nonProxyHosts>www.anything.com|*.somewhere.com</nonProxyHosts>
            </proxy>    
        </proxies>
        
      3. 2) Under the ‘servers’ section, specify a remote Maven server called remoteRepository. This will hold the username/password details when connecting to the ‘remoteRepository’, i.e. our DevCS Maven Repository :
      4. <servers>
            <server>
              <id>remoteRepository</id>
              <username>USERNAME</username>
              <password>PASSWORD_IN_PLAINTEXT</password>
            </server>
        </servers> 
        
      5. The DevCS Maven Repository is protected, and only users who have access to the project can view the associated repository. The authentication mechanism is basic HTTP. The username/password above will be used for authentication before the upload.

      6. 3) Under the ‘profiles’ section, specify the default value of ‘remoteRepository’, as mentioned below:
      7. <profiles>
         <profile>
            <id>default</id>
            <repositories>
              <repository>
                <id>remoteRepository</id>
                <name>Remote Weblogic Repository</name>
                 <url>dav:https://developer.us2.oraclecloud.com/……/maven/</url>
               <layout>default</layout>
              </repository>
            </repositories>
          </profile>    
        </profiles>
        

        The ‘url’ above can be found on the DevCS home page, as seen in the above image. Also note the ‘dav:’ in the URL, signifying that the upload will use the WebDAV protocol.

      8. 4) Make sure the default profile is activated :
      9. <activeProfiles>
          <activeProfile>default</activeProfile>
        </activeProfiles>
        

b) Installing Weblogic binaries on the local machine

    1. i. Download the Weblogic 12.1.2 ‘Zip distribution for Mac OSX, Windows, and Linux’ from Oracle Technology Downloads . We used the zip distribution only for demonstration purposes, any other type of installation would work as well.

 

    1. ii. Unzip the downloaded file to any location (eg: /home/myhome/mywls ).

 

    1. iii. Set JAVA_HOME and MW_HOME, eg :
      1. 1) $export JAVA_HOME=/home/myhome/myjavahome
      2. 2) $export MW_HOME=/home/myhome/mywls/wls12120

 

  1. iv. Run MW_HOME/configure.sh . This unpacks all the jar files

c) Pushing the local weblogic binaries to the remote maven repository

    1. i. On the local VM, ensure MVN_HOME/bin is available in the $PATH variable

 

    1. ii. ‘cd’ to location ‘/home/myhome/mywls/wls12120/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.1.2’

 

    1. iii. Create a file, pom.xml , with the following content :

 

    1. <project>
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.mycompany.oracle</groupId>
        <artifactId>my-app</artifactId>
        <!--The version, groupId, artifactId above can be anything. -->
        <version>1</version>
      	<build>
      		<extensions>
      			<extension>
      				<artifactId>wagon-webdav-jackrabbit</artifactId>
      				<groupId>org.apache.maven.wagon</groupId>
      				<version>1.0-beta-7</version>
      			</extension>
      		</extensions>
      	</build>  
      </project>
      

      The above pom.xml declares the wagon webdav plugin to be part of the mvn context. This library is used for uploading content to the remote repository using the WebDAV protocol.

    2. iv. Run the command :
    3. mvn deploy:deploy-file -DpomFile=oracle-maven-sync.12.1.2.pom -Dfile=oracle-maven-sync.12.1.2.jar
       -DrepositoryId=remoteRepository   -X  -Durl=dav:https://developer.us2.oraclecloud.com/……/maven/
    4. This populates the local Maven repository, and deploys the file oracle-maven-sync.12.1.2.jar, its associated pom, and the MD5 and SHA1 hash of each to the remote repository specified by the -Durl parameter. The -DrepositoryId is used to pick up the authentication information from settings.xml (which we set above in Section a.2).

 

  1. v. Run the command :
  2. mvn com.oracle.maven:oracle-maven-sync:push 
    -Doracle-maven-sync.oracleHome=/home/myhome/mywls/wls12120  
    -Doracle-maven-sync.serverId=remoteRepository
  3. This command invokes the ‘Oracle Maven Synchronization Plugin’, specifically the coordinate com.oracle.maven:oracle-maven-sync:push , which uploads the local weblogic jars to the remote repository. This command recursively traverses through various dependencies and uploads them all. Depending on the network connection/upload speed, this may take a couple of hours.
  4. Please note that this command uses the pom.xml file defined in step#iii above.

Use Maven to compile, package and deploy a java application to JCS-SX

We assume that the source java project is checked into the DevCS GIT repository.
The following pom.xml can be used for compiling and packaging the project. It must also be checked into the GIT repository.

<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>com.oracle.samples</groupId>
	<artifactId>simpleJavaApplication</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>war</packaging>
	<name>simpleJavaApplication</name>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.oracle.weblogic</groupId>
			<artifactId>weblogic-server-pom</artifactId>
			<version>12.1.2-0-0</version>
			<type>pom</type>
			<scope>provided</scope>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
				</configuration>
			</plugin>
			</plugins>
	</build>
	  <repositories>
		<repository>
		  <id>remoteRepository</id>
		  <url>https://developer.us2.oraclecloud.com/……/maven/</url>
		  <layout>default</layout>
		</repository>
	  </repositories>
	  <pluginRepositories>
		<pluginRepository>
		  <id>remoteRepository</id>
		  <url>https://developer.us2.oraclecloud.com/……/maven/</url>	
		</pluginRepository>
	  </pluginRepositories>	 
</project> 

The things to note are :

  • The com.oracle.weblogic and junit dependencies
  • Maven compiler plugin which lets us specify the -source and -target options while using javac (optional)
  • Maven Repository url that specifies the location of the Weblogic libraries (i.e. the repository we just populated)

Below are the steps for setting up the Hudson build and deployment options on DevCS:

  1. a) On the DevCS project home page, click on the ‘Build’ tab, and create a new job
  2. 2) Name the new job. On the configurations page, set the following :
    1. a) JDK Version
    2. b) Git Repository details
    3. c) Create a Maven 3 Build Step and specify ‘clean package’ as the goals. Also ensure the pom.xml file is specified correctly.
    4. d) In the post-build step check the ‘Arhive the artifacts’ option, specifying the file(s) to be archived, as shown below . The archived file(s) will be used to deploy the generated artifacts to the associated JCS-SX instance.
    5. Save the job. Run it once to make sure the build executes successfully
  3. 3) Go to the ‘Deploy’ tab and create a new Deployment Configuration :
  4. The options in the image above are self-explanatory. The application ‘TestConfiguration’ is to be deployed to the JCS-SX instance ‘jcssx02′. The artifacts generated from the specific Hudson job and build number are deployed to the ‘jcssx02’ instance. One can also schedule an Automatic deployment (as compared to ‘On Demand’) on every successful Hudson build.

Conclusion

We’ve demonstrated how to use the Developer Cloud Service to automate your Maven based development lifecycle. We saw how the Maven Repository can be populated with weblogic or other custom jars, and how the Hudson build jobs and deployments can be configured.

We’d be remiss if we didn’t mention the newly introduced Oracle Maven Repository . Steve Button explains it nicely in his blog https://blogs.oracle.com/WebLogicServer/entry/weblogic_server_and_the_oracle . Efforts are underway to make the Oracle Maven Repository work with DevCS. More on that when we have more information.

Comments

  1. The above reported problem was because I had defined the incorrectly in my settings.xml:

    4) Make sure the default profile is activated :

    default

    Thanks Ashish for helping me resolve this issue.

  2. I was able to successfully deploy the oracle-maven-sync.12.1.3.jar and pom to my DevCS. However, I’m having trouble running the push command:

    It’s failing with:

    [ERROR] Failed to execute goal com.oracle.maven:oracle-maven-sync:12.1.3-0-0:push (default-cli) on project my-app: Synchronization execution failed: Failed to install and/or deploy “com.oracle.weblogic:ant:jar:12.1.3-0-0
    [ERROR] Update Time: 20140521225142
    [ERROR] POM File: e:\oracle\soa12c\wlserver\plugins\maven\com\oracle\weblogic\ant\12.1.3\ant.12.1.3.pom Real File: e:\oracle\soa12c\oracle_common\modules\org.apache.ant_1.9.2\lib\ant.jar”. Repository copy will not be performed for this artifact: Could not find a server with ID remoteRepository in project-injected remote repository data. Creating one from scratch. You may experience permission or other configuration problems. Check your settings.xml.

    I’m not sure what the message “Could not find a server with ID remoteRepository in project-injected remote repository data” means, or if it’s even a problem. I have remoteRepository defined in my settings.xml as it was successfully used to deploy the oracle-maven-sync.jar and pom.

    Any thoughts?

Add Your Comment