Tiven Wang
chevron_rightHCP chevron_rightMaven chevron_rightJava

Setup Java Maven Project for HANA Cloud Platform

Wang Tiven February 23, 2017
425 favorite favorites
bookmark bookmark
share share

The project codes for this article can be downloaded from Github.

Development Environment

  • JDK 1.7
  • Maven 3.+
  • Eclipse with Maven plugins


Maven Project Initialization

You will need somewhere for your project to reside, create a directory somewhere and start a shell in that directory. On your command line, execute the following Maven goal:

mvn -B archetype:generate \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DgroupId=com.mycompany.app \

For our project using

mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.sap.c4c -DartifactId=wechat

cd wechat

Just execute the compile command to check the project

mvn compile

Add Servlet

In order to run in web application server, the project need web servlet to process http request and add the Java Web API dependencies.

Add Web API Dependencies

Add the Java Web API by the SAP Cloud Java Web API dependence.

  <!-- The SAP HANA Cloud Platform Java Web Tomcat 7 API -->

Create Servlet

Create a Java servlet class to print a simple words “Hello World!” for http response.

package com.sap.c4c.wechat.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

 * Servlet implementing simplest possible hello world application for SAP HANA Cloud Platform.
public class MessageServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /** {@inheritDoc} */
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().println("<p>Hello World!</p>");

Add Web Content

Add the Web Content files in folder WebContent/ and the servlet configurations in file WEB-INF/web.xml

<!-- Main sample servlet mapped to / so that the integration test harness can detect readiness (generic for all samples) -->

Maven Build Plugins

In order to package Java war artifact, you need add the maven war and compiler plugins to rewrite the default configurations.

      <!-- Map the Eclipse file system layout to the Maven plug-ins -->

      <!-- Set compiler to officially supported JDK version for the given SAP HANA Cloud Platform SDK -->

Test Locally

Tomcat Maven Plugin

The Tomcat7 Maven Plugin provides goals to manipulate WAR projects within the Tomcat servlet container version 7.x.


Run tomcat7 container using mvn tomcat7:run then access the project by http://localhost:8080/wechat/

Build and Package

In maven command or the eclipse maven tools to execute the maven goal mvn package to build and package the project to Java war artifact. Once completed the maven goal, you can find the war artifact in /target/wechat.war


Deploy Manually

Upload or update the Java war artifact on HANA Cloud with the cockpit.

Deploy from Eclipse

Deploying on the Cloud from Eclipse IDE

Deploy with Console Client

Deploying on the Cloud with the Console Client

Similar Posts


Back to Top