Step 1: Open your Eclipse IDE
The first step in building your application is to create a new Dynamic Web Project. Open your Eclipse IDE with the installed SAP Cloud Platform Tools. Make sure the Java EE perspective is open by choosing Window > Open Perspective > Other.
Step 2: Choose Java EE (Default)
Then choose the perspective Java EE (Default) and confirm by clicking OK.
The J2EE perspective is now open.
Step 3: Open Dynamic Web Project
In the Eclipse main menu choose File > New > Dynamic Web Project to open the respective wizard.
Step 4: Set project name
In the New Dynamic Web Project Wizard define the Project name to be helloworld
. Make sure the Target Runtime is set to Java Web
, the Server Runtime Environment that has been created in the tutorial Configuring Eclipse with SAP Cloud Platform Tools for Java. Leave all other settings untouched and click Finish to create the project.
The helloworld
project is now ready for your code.
Step 5: Create new servlet
In Java EE, web applications are implemented as Servlets
. On the newly created helloworld
project node, open the context menu with a right-click and choose New > Servlet to open the Create Servlet wizard.
Step 6: Set class name
In the Create Servlet wizard enter helloworld
as Java package and HelloWorldServlet
as Class name. This will create Java classes with the respective package and name. Choose Next.
Step 7: Set URL mapping
You will want this Servlet to be accessible via the URL <servername>/helloworld
, for example http://localhost:8080/helloworld
. For this we will set the URL mapping to \
. For this select /HelloWorldServlet
in the URL mappings field and choose Edit.
Step 8: Change URL pattern
In the Pattern field, replace the current value with just /
. Confirm with OK.
Step 9: Generate servlet
Click Finish to generate the servlet.
Step 10: Servlet opening
The Java Editor will open the corresponding HelloWorldServlet
class in the editor pane. You will also find the Servlet
under the helloworld
project node > Java Resources > src
> helloworld
> HelloWorldServlet.java
Step 11: Write hello world code
Next, you will edit the Servlet to output the classical “Hello World”. For this you will modify the doGet()
method and add the following code and save your changes.
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().println("Hello World!");
}
The application is now ready to run.
Step 12: Run on server
To test your application before deploying it to the SAP Cloud Platform you can run it on a local runtime. To do this, do the following:
Navigate to your HelloWorldServlet.java
via the helloworld
project node > Java Resources > src
> helloworld
> HelloWorldServlet.java
. Open the context menu on the Servlet
with a right-click and choose the Run on Server option.
Step 13: Manually define server
Make sure that Manually define a new server is selected and choose SAP > Java Web Server as server type. Leave all other settings unchanged and click Finish.
Step 14: View running server
A local server will start with your helloworld
application deployed. After the server is ready your application will be opened in a browser within Eclipse and greet you with “Hello World!”. In the Servers view you can also see the running server with your application deployed.
Step 15: Run on the SAP Cloud Platform
To run your application on the SAP Cloud Platform you will choose a different server to run it. Again, navigate to your HelloWorldServlet.java
via the helloworld
project node > Java Resources > src
> helloworld
> HelloWorldServlet.java
. Open the context menu on the Servlet with a right-click and choose the Run on Server option.
Step 16: Select SAP Cloud Platform as server type
As before, make sure that Manually define a new server is selected. This time choose SAP > SAP Cloud Platform as server type. Make sure to set the Landscape host to hanatrial.ondemand.com
. Leave all other settings unchanged and choose Next.
Note: The used Landscape host hanatrial.ondemand.com
is only valid if you are using a free Developer Account. Please change the landscape host if you want to use a productive account. The respective landscape hosts can be found in the official documentation.
Step 17: Specify the Application name
On the next wizard page specify the Application name to be helloworld
, provide the login information for your SAP Cloud Platform account and click Finish:
Field Name |
Value |
Account Name |
Your SAP Cloud Platform account name, for example p1234567890trial |
Username |
Your SAP Cloud Platform account name, for example p1234567890 and your password |
Step 18: View running server
A Cloud server will start that has your helloworld
application deployed. After the server is ready your application will be opened in a browser in Eclipse and greet you with Hello World!. In the Servers view you can also see the running server with your application deployed
Congratulations: You have your first application running on the SAP Cloud Platform!
Optional
Now that you are familiar with the basic routine of developing applications and deploying them locally and to the cloud, you may want to check out the samples provided as part of the SAP Cloud Platform SDK.
Related Information
Next Steps