Skip to Content

Once the SAP client is installed, developing with it is relatively simple. Here we’ll go on a walkthrough of developing a simple applet for the SAP Cloud Platform.

STEP 1: Setting the Perspective

Open the Eclipse IDE in which the SAP Cloud Platform is installed and ensure that the Java EE perspective is set by going to Window -> Open Perspective -> Other. In the pop-up box that follows select Java EE and waits for it to change the layout. Once the J2EE layout perspective is arranged we can move on to actual development.

STEP 2: Start a New Dynamic Web Project Wizard

In the main menu of Eclipse, choose File -> New -> Dynamic Web Project. In the following New Dynamic Project box, change the Project Name to HelloWorld. In the dropdown for Target Runtime just below that, make sure it’s set to Java Web. Leave all other settings as-is and click on Finish.

STEP 3: Create the Servlet

All Java EE projects run snippets of code called servlets. In the Project Explorer sidebar, you should see the HelloWorld project. Right click on it and select New -> Servlet. The Create Servlet window will pop-up. In there the Java package name should be changed to HelloWorld and the Class Name should be HelloWorldServlet. We now hit the Next button to move to the next page. This page will have a field near to the bottom titled URL Mappings. We want to select the /HelloWorldServlet entry and hit the Edit button on that box. The Pattern Field box will come up and you should replace whatever value is in it with a / then select Okay. After we do this, we hit Finish to complete the servlet generation.

STEP 4: Coding the Servlet

The Servlet will automatically open in the editor window, but even if it doesn’t we can easily find it in the Project Explorer window by expanding the HelloWorld project and opening Java Resources ->src ->helloworld -> HelloWorldServlet.java. The code that goes into this servlet is as follows:

/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

response.getWriter().println(“Hello World!”);

}

This code snippet goes at the very bottom of the pre-generated code visible in the editor. Once it is complete, we’re ready to run our servlet.

STEP 5: Running on the Server

Debugging is a huge part of ensuring that your apps work properly and with a Java project, running it on a server is the best way to test such a project. In the Project Explorer, expand the project completely and locate the HelloWorldServlet.java file, then right-click on it, go running As and select Run on Server. The Run on Server box will pop up and here we can define what type of server we want our servlet to run on. Select Manually Define a New Server if it hasn’t already been selected for you, then underneath that ensure that Java Web server is highlighted. Leave everything else as-is and hit the Finish button. As soon as the server has been assigned, a browser within Eclipse will open showing you your output. In the Servers view along the bottom pane you can also see the server running the application.

STEP 6: Deployment of the SAP Cloud

After we’ve gotten our servlet working properly, it’s time to look at making it a Cloud-Based application. To change it from a regular Java servlet to one running on the cloud is simply a matter of changing the server it runs on. We will once again right click on the HelloWorldServlet.java file and select Run As and Run on Server. When the box pops up this time we change the server type to SAP HANA Cloud Platform which will define our server as the SAP server which we intend to run this servlet on. The Landscape Host description box should say hanatrial.ondemand.com if you’re using a free demo account. If you have a productive working account, then consult the documentation to locate your server location. After we set these things up, we hit Next. On the next page, you will be prompted for an Application Name which you can enter as HelloWorld and an Account Name, User Name and Password. All of these would vary based on your own personal SAP account. Once the details are filled out we hit Finish. The server will start on the cloud and your output window will open up in Eclipse as did previously. Under the Servers tab in the lower pane, just as before, you should be able to see details of the running server.

At the end of this deployment, you should have a general idea of how to run your completed Java projects onto the cloud. It’s really not that complicated, and even a beginner at Java can get basic apps programmed and running within the cloud. Java’s use of servers makes life easy for programmers who would like to use a cloud server for their deployment and SAP Cloud Platform is perfect for those sorts of tasks.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply