πŸ“œ ⬆️ ⬇️

How to run servlets from Eclipse on the SAP Cloud Platform


This is the fourth publication in the framework of the assistance to the participants of the competition β€œSAP Koder-2017” .


You want to try the SAP Cloud Platform, but you are used to working in Eclipse. No problems! You can explore the new features in the most comfortable conditions. But all in order.
Today we will look at how to develop a servlet in Eclipse and run it in the SAP Cloud Platform.


Step 1. To begin with we will be defined with Java and Eclipse versions. SAP recommends using Java 7 for Eclipse Mars (4.5). So do. Java 7 can be downloaded from here . Eclipse Mars take here . Following the classic script for Windows applications, we install both.

Step 2. If you have not worked with the SAP Cloud Platform, then first you need to register . For non-commercial use by individual developers, SAP provides free, perpetual access to the SAP Cloud Platform.
')
"What is the catch?" - you ask. SAP imposes certain restrictions on the amount of resources provided, for example, 1 GB of memory for HANA, 1 database instance, 100 MB for the repository, 2 mobile applications, and more. All details are on the SAP website .

After registration, you can login to the SAP Cloud Platform. Your SCP account home page looks like this.



Here note that the username and account may differ (in the screenshot are underlined by red lines).

Step 3. Connecting Eclipse to the SAP Cloud Platform server. To do this, launch Eclipse, then choose Window β†’ Preferences . In the Preferences window that opens, on the left, select Server β†’ SAP Cloud Platform. Fill in the following fields
Landscape host: hanatrial.ondemand.com
Account name: <your free account name from step 2>
User name: <username of your free account from step 2> .



Please note that these field values ​​can only be used for a free account. To connect to the productive SAP Cloud Platform server, use a different server name and a different account.

Step 3. Now connect the SAP libraries to Eclipse. SAP provides several versions of the SCP SDK for Java development: Java Web, Java Web Tomcat 7, Java Web Tomcat 8, Java EE 6 Web Profile. Which version of the SDK to choose depends on the task. For this example, I downloaded Java Web , Java Web Tomcat 7, and Java EE 6 Web Profile . Download and unpack archives. Further in Eclipse, in the same Window β†’ Preferences menu, select Server β†’ Runtime Environment and add libraries.



Step 4. The SAP Cloud Platform uses its own version of the JVM. SAP JVM is a fully certified Java Standard Edition Virtual Machine for Java 7, developed on the basis of Oracle HotSpot VM and JDK and equipped with additional features such as the SAP JVM Profiler for setting up and monitoring applications running on the SAP Cloud Platform. For consistency in your development and launch environment, you can deploy SAP JVM locally and connect to Eclipse. To do this, download the SAP JVM and unpack the archive. Further in Eclipse in the Window β†’ Preferences menu, select Java β†’ Installed JREs.



Click Add, in the window that opens, select Standard VM, click Next



and select the folder where you just unpacked the JVM.



You can specify SAP JVM as your primary runtime (i.e. default).



Step 5. We set up Eclipse, connect all the libraries of the SAP SDK. In order not to deviate from tradition, let's now create a HelloWorld application based on Java servlets. To do this in Eclipse create a Dynamic Web Project .



Let's call the project HelloWorld.



Next, add a servlet to the project.



Set the following values ​​for the fields

Java package: hello
Class name: HelloWorldServlet



For ease of reference, you can simplify URL mappings .



To do this, select / HelloWorldServlet and replace it with / .



Replace the code in the doGet (...) method with
response.getWriter (). println ("Hello World!");



Step 6. The application is ready. The last step is to launch the application on the SAP Cloud Platform. To do this, select the menu Run β†’ Run As β†’ Run on Server .



In the window that appears, manually select the SAP Cloud Platform server



In the next step, you will need to enter your SCP account name, username and password.



Step 7. In conclusion, let's go to the SAP Cloud Platform and find our application there.



In SAP Cloud Cockpit, we see that two applications are running in the account.



Choose our application. The control and monitoring panel opens where you can find out the URL of the application.



and run it in a separate window.


Good luck in using the SAP Cloud Platform!

Source: https://habr.com/ru/post/327510/


All Articles