Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

As SAP NetWeaver Cloud is a platform for Java web applications, there is no problem with deploying web application initially running in another framework coming from the wider JVM-supported languages family, e.g. web applications written in Groovy and Grails. With a few minor adjustments and the help of SAP NetWeaver Cloud Deployment Plugin for Maven, I will show how to automate the deployment process of Grails application.

Prerequisites

I was using the latest Grails version to date (2.1.1). It comes with useful updates that would be helpful in this scenario, like simplified way to convert non-mavenized Grails app by creating for us pom.xml with all necessary configuration and dependencies. You should also have a Maven installation on your machine. I was using version 3.0.4, but the example should run with most versions of Maven (I would assume all 2.x and 3.x versions should work fine, I haven't spotted any restrictions from the SAP NetWeaver Cloud Deployment Plugin, but to be sure you should probably have at least version 3.x).

Installing SAP NetWeaver Cloud Deployment Plugin for Maven

To simplify NetWeaver Cloud deployment tasks in Maven, there is great nwcloud-maven-plugin. The easiest way to get it is to clone the Git repository from its GitHub page. Afterwards you just need to install it into your local Maven repository by simply running Maven install command in the project directory:

> mvn install

And that's all. Now you will be able to use the plugin in your Maven projects.

Creating Grails Project

We start by creating standard Grails application. I will create application called hello-grails:

> grails create-app hello-grails

Now we need to "mavenize" project and here comes the new Grails command create-pom:

> cd hello-grails

> grails create-pom com.sap

The only parameter of this command is the group id (here I put com.sap) for the Maven bundle. Maven artifact id is taken by default from the Grails project name (so in our example it is hello-grails).

Configuring SAP NetWeaver Cloud Deployment Plugin

To use the plugin you need to add following lines in the build/plugins section of the project's pom.xml:

  <build>  

   

    ..

   

    <plugins>

      ..

      

      <plugin>

        <groupId>com.sap.research</groupId>

        <artifactId>nwcloud-maven-plugin</artifactId>

        <version>1.0.0.RELEASE</version>

        <executions>

          <execution>

            <id>after.package</id>

            <phase>package</phase>

            <goals>

              <goal>hint</goal>

            </goals>

          </execution>

        </executions>

      </plugin>

     

    ..

    

    </plugins>

   

    ..

    

  </build>

Plugin requires an external configuration file nwcloud.properties that should be put in the project root directory.

Example of this configuration can be found on the plugin GitHub page. To keep things simple, I pasted below the main properties that are necessary to deploy the application on NetWeaver Cloud:

sdk.dir=C:\\nwcloud\\neo-sdk-1.13.1

host=https://netweaver.ondemand.com

account=<NWCLOUD_ACCOUNT>

application=<NWCLOUD_APP_NAME>

user=<NWCLOUD_USER>

synchronous=true

You should adjust this properties to your local settings (e.g. NetWeaver Cloud SDK path - the directory where you unpacked the SDK, your account name, desired application name and user name). Avoid putting your NetWeaver Cloudpassword in the properties file, as it may eventually end up in your code repository, which could make it visible to the other people. If you omit the passowrd in the properties file, you will be anyway asked to provide it dierctly in the command prompt during the deployment process.

Adjusting Grails Application and Deployment

Now we just need to add a few changes to our Grails application to make it deployable on NetWeaver Cloud. Without any changes to the project there appears to be a problem with MANIFEST.MF file in the war file with the Grails application. Basically NetWeaver Cloud complains about unsatisfied dependencies coming from Import-Package entries in the manifest:

     [java] Deployment finished with error !

     [java] The Installable unit hello-grails[0.0.0] could not be deployed because of unsatisfied dependencies.

     [java] The following error messages were returned by the provisioning framework:

     [java] Cannot complete the install because one or more required items could not be found.

     [java]    Software being installed: Merged Product 0.0.1 (hello-grails.merged.product 0.0.1)

     [java]    Missing requirement: hello-grails 0.0.0 requires 'package javax.servlet [2.5.0,3.0.0)' but it could not be found

     [java]    Cannot satisfy dependency:

     [java]       From: Merged Product 0.0.1 (hello-grails.merged.product 0.0.1)

     [java]       To: hello-grails 0.0.0

     [java]

     [java]

     [java] Failed to execute command [deploy]

     [java] Java Result: 132

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 28.850s

[INFO] Finished at: Fri Nov 23 11:46:42 CET 2012

[INFO] Final Memory: 6M/20M

[INFO] ------------------------------------------------------------------------

As you can see, Maven ends up with "BUILD SUCCESS" message, however the deployment was unsuccessful. This is one shortcoming of the SAP NetWeaver Cloud Deployment Plugin, so for the time being always look carefully at the last few console log lines after using plugin commands, as just seeing successful build message could be sometimes misleading.

To fix this issue we need to provide a clean version of the manifest. I got the original file from the SDK samples, but its content is very simple so you can just copy the snippet below into <project-root>/web-app/META-INF/MANIFEST.MF (you need to create this file on your own):

Manifest-Version: 1.0

Class-Path:

Otherwise you can just take the file from the hello-world project in the SKD samples (<NWCLOUD_SDK_HOME>\samples\hello-world\WebContent\META-INF\MANIFEST.MF).

I have put this file in the empty web-app/META-INF directory that you can find in our hello-grails project root. However Grails still creates its own manifest file during the packaging phase so there is a need to instruct the build process to use our custom manifest. This can be achieved by hooking into Grails build event as explained in the documentation. I have also found a forum thread explaining similar problem, however the level of manifest customization there was a bit different as the person wanted to modify specific fields in the manifest file (nevertheless the event name suggested at the end of the thread was very helpful). Here we just need to overwrite the whole file, so it is much simpler. As explained in the documentation and that thread, create _Events.groovy file in the scripts directory under the project root with the following content:

eventCreateWarStart = { warName, stagingDir ->

    ant.copy(todir: "$stagingDir/META-INF", file: "web-app/META-INF/MANIFEST.MF", overwrite: true)

}

After this step we are now able to deploy the application.

First, create the war file with the app content:

> mvn package

and now you can deploy and start NetWeaver Cloud application, thanks to SAP NetWeaver Cloud Deployment Plugin commands:

> mvn nwcloud:deploy nwcloud:start

You should be prompted for your NetWeaver Cloud password (unless you put it in your nwcloud.properties file, which - again - is a bad idea!)

After successful deployment you can check the running application by opening the address that should be printed on the console at the end of the process (you need to add at the end of this address the "/" character and the Groovy application name, in this case /hello-grails😞

1 Comment
Labels in this area