Technical Articles
Step 2 with SAP Cloud SDK: HelloWorld on SCP Neo
Disclaimer:
This blog post is only applicable for the latest version 2 of the SAP Cloud SDK. You can find an updated tutorial for version 3 over at our tutorial page.
The following steps will explain how to create the very first HelloWorld example on SCP Neo using the SAP Cloud SDK. If you want to follow this tutorial, we highly recommend checking out the first part of this blog series. You will not need any additional software as the server will run on your local machine.
Note: This post is part of a series. For a complete overview visit the SAP Cloud SDK Overview.
Goal of this blog post
The tutorial will show you the first steps when developing applications for the SCP Neo using the SAP Cloud SDK. To be precise, we will cover the following steps:
- Generate a project stub using a Maven Archetype
- Understand the project structure and its artifacts
- Implement and understand the Hello World Servlet
- Implement and understand the integration test
- Deployment
Generate Project from Archetype
Since you have already installed Maven, you can use it to generate a project stub from the SAP Cloud SDK Maven archetype. Just use your console (e.g. IDE, OS, navigate to a parent directory for your project and run the following command.
mvn archetype:generate -DarchetypeGroupId=com.sap.cloud.s4hana.archetypes -DarchetypeArtifactId=scp-neo-javaee7 -DarchetypeVersion=RELEASE
Once the generation process is started, Maven will ask you for the usual module parameters:
groupId | an identifier representing your group, company or organization (e.g. com.sap.cloud.sdk.tutorial ) |
artifactId | an identifier for your application (e.g. firstapp ). For the tutorials we suppose you have chosen “firstapp “. |
version | the version of your application (e.g. 1.0-SNAPSHOT ) |
package | the name of the top-level package your source code will reside in (typically equal to your groupId, e.g. com.sap.cloud.sdk.tutorial ). Please pay attention to package and directory names in any upcoming source code when using a different package name than suggested here. |
After the required values are provided, Maven will generate the new project from the Cloud SDK archetype:
Now you can work with it just like any other Maven project.
cd /path/to/firstapp
mvn clean install
Understand the project structure and its artifacts
Once the Maven project is generated, you can open your favorite IDE and load the project as “Maven Project”. After importing the project into your IDE, the overall structure will look like this:
The first thing you will notice, is the different directories:
application
cx-server
integration-tests
unit-tests
These are Maven sub-modules and they serve different aspects of your code application, test and deployment environment. The following separation of modules makes it possible to run dedicated unit tests and sensitive integration tests without deploying the application.
Multiple-modules project
The advantage of operating a multiple-modules project for your application becomes apparent as soon as the software complexity rises. Then it gets convenient to dedicate code distribution and responsibility to developers for either application or test environment. In terms of reliability and continuance, you will see, that front-end testing and test-automation are as important as classic backend-testing of your project. These fields of expertise require different programming paradigms, and such different kinds of development life cycles. To ensure the overall software stability and liability, a multiple-modules setup is the best practice solution.
To get you started, we take a look into the conventional application project, as well as the classic unit tests. Then the integration tests follow, used for code tests with external servers and resources. Once software testing is covered, we briefly introduce the Cx server for continuous integration and delivery.
application
contains the source code and configuration of your actual web application.
src/main/java Here goes your production code, nothing else. As you can see, there’s already the HelloWorldServlet
, which we will look at in more detail soon.src/main/resources Anything that you require in your production code but is no compilable code goes here (typically things like API definition files for RAML or OpenAPI, Database Migration Files for Flyway or Liquibase) src/main/webapp contains the deployment descriptor for your web application – the infamous web.xml
, as well as a starter web page inindex.html
.src/test/resources Additional resources for attached test classes. pom.xml This is your project management file for Maven where you can maintain other open source dependencies or use plugins that ease your build Environment. unit-tests
contains the unit tests for your application. Its structure is similar toapplication
but it exclusively holds test classes and resources. The purpose of this module is to test and validate single aspects of data flow and computational operations in theapplication
project.
src/test/java This is the place for your automated tests. src/test/resources Tests may also require additional resources to work properly such as configuration files. This is their place. integration-tests
contains the integration tests for your application. Its structure is similar toapplication
.
src/test/java Here you can put all your integration tests. As you can see, there’s already the HelloWorldServiceTest
corresponding to theHelloWorldServlet.
src/test/resources Here are all the resources needed for the integration tests to run or validate. cx-server
contains the script and configuration file to manage your best practice continuous integration and delivery software environment (Cx
). The including files allow Linux users to simply create your very own Cx server as part of a Docker deployment. The server, which will be run, is Jenkins. This automation server helps to manage all technical steps of a software development process.
cx-server This Unix bash
script allows you to start and stop the Jenkins server on your local machine, as part of a Docker container.server.cfg This is the configuration file for the server parameters. Once a Jenkins server is configured for your personal needs, the files in the project root directory become useful:
Jenkinsfile This text file contains the definition of a Jenkins Pipeline and stays part of your project source code. It defines what steps are run specifically for your application. pipeline_config.yml This is the configuration file for your specific application.
Unit tests and integration tests
This separation of test modules makes it possible to just run unit tests and integrations test without deploying, as well as deploying the application without running time consuming tests. Unit tests can either be kept publicly inside the application module, or in the separate unit-tests
folder, that’s part of the archetype. For that topic we highly recommend the articles and educational videos from Martin Fowler. For a start we advice reading his post about Unit Tests.
During development it becomes important to test newly implemented code to external services, i.e. logic running in a distributed environment. This is where an integration test is an important tool to ensure correctness and stability over the whole internal and external deployment. Since the integration tests may contain confidential information, like business logic and test access tokens, it can be helpful to maintain its operation inside a dedicated Maven sub module. That way the runnable application itself can be later shipped without tests and their dependency.
HelloWorldServlet
Now that you understand the project structure, take a closer look at the HelloWorldServlet.java
package com.sap.cloud.sdk.tutorial;
import org.slf4j.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import com.sap.cloud.sdk.cloudplatform.logging.CloudLoggerFactory;
@WebServlet("/hello")
public class HelloWorldServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private static final Logger logger = CloudLoggerFactory.getLogger(HelloWorldServlet.class);
@Override
protected void doGet( final HttpServletRequest request, final HttpServletResponse response )
throws ServletException, IOException
{
logger.info("I am running!");
response.getWriter().write("Hello World!");
}
}
The HelloWorldServlet
extends HttpServlet
, so this will be a HTTP endpoint that we can visit. We map this endpoint to the /hello
route using @WebServlet("/hello")
.
By overriding the function doGet
, we define what happens when a client performs an HTTP GET request on the /hello
route. in this case we simply write a response containing “Hello World!”.
Integration test
Let’s take a look into the integration test project. It already contains a test for our simple HelloWorldServlet:
package com.sap.cloud.sdk.tutorial;
import com.jayway.restassured.RestAssured;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.net.URL;
import com.sap.cloud.sdk.testutil.MockUtil;
import static com.jayway.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith( Arquillian.class )
public class HelloWorldServiceTest
{
private static final MockUtil mockUtil = new MockUtil();
@ArquillianResource
private URL baseUrl;
@Deployment
public static WebArchive createDeployment()
{
return TestUtil.createDeployment(HelloWorldServlet.class);
}
@BeforeClass
public static void beforeClass()
{
mockUtil.mockDefaults();
}
@Before
public void before()
{
RestAssured.baseURI = baseUrl.toExternalForm();
}
@Test
public void testService()
{
final String body = given().get("/hello").body().asString();
assertThat(body).isEqualToIgnoringCase("Hello World!");
}
}
As you can see, HelloWorldServiceTest
uses JUnit to define the test.
- It declares
BeforeClass
andDeployment
for the general test setup. - The
MockUtil
provides easy access to mocked backend systems, e.g. preconfigured ERP connections for the test cases. - A
WebArchive
is deployed as a test run setup, including predefined additional classes, here:HelloWorldServlet.class
- The integration test features
RestAssured
to easily run WebService calls over HTTP. Later you will see the advantages of having this library on hand, when dealing with more sophisticated examples. Here it runs an assertion test on the result of a GET request to the local /hello route.
Deployment
It is time to finally deploy the application.
Local deployment
To run all required Maven goals, you can use the following commands in the project root path, i.e. parent module:
mvn clean install
mvn scp:clean scp:push -pl application
The first command will cascade the goal execution of clean
and install
to both Maven sub modules. It will break in case of any compilation errors or test failures.
The second command will run a cleanup and startup for the SCP Neo application. The -pl
argument defines the project location in which the Maven goals are being executed. If there is already a previously started instance of the application running, the goal scp:clean
will try to stop it on localhost:8080
and will remove the cached server files of the application. scp:push
will start the application on localhost:8080
. The web server is started as background process and will take additional seconds to initialize.
The second command will also ask for URL, user and password for the destination “ErpQueryEndpoint”. Since this destination is not used at this point of the tutorial, any arbitrary value can be entered here, e.g. “dummy”.
Once a couple of seconds have passed, you can open a browser and go to http://localhost:8080/firstapp-application/
- You will be greeted with a login screen.
- Enter
test
/test
Follow the link to the HelloWorldServlet:
Hello world!
That’s it.
When you are done and want to close the local SCP deployment, please use the scp:clean
command for the application project. It will close any connection and stop the server.
mvn scp:clean -pl application
Remote deployment
As a requirement make sure to have the Neo CLI for the Java EE 6 Web Profile available. The tool is downloaded as part of the local deployment described above (see folder application/scp/sdk-<version>/tools), but you can also download it separately. A traditional installation is not required:
The Neo CLI comes packaged with the SAP Cloud Platform Neo Environment SDK
- Go to https://tools.hana.ondemand.com/#cloud
- Download and unzip the latest neo-javaee7-wp-sdk-######.zip alias “Java EE 7 Web Profile”
- Go into the directory “tools” and find the neo.bat (Windows) or neo.sh (Mac/Linux)
Please consider the documentation or readme.txt file in case you use a proxy server for connecting to the host. Also we recommend adding this tools directory to your
PATH
variable, in order to run its executables from any location.
Once you open your Neo platform website, you will see your account name as well as the hostname of the service.
The hostname is usually depending on your general location:
Europe (Rot) – Trial | hanatrial.ondemand.com |
Europe (Rot) | eu1.hana.ondemand.com |
US West (Chandler) | us2.hana.ondemand.com |
US East (Ashburn) | us1.hana.ondemand.com |
US East (Sterling) | us3.hana.ondemand.com |
Japan (Tokyo) | jp1.hana.ondemand.com |
China (Shanghai) | cn1.hana.ondemand.com |
Australia (Sydney) | ap1.hana.ondemand.com |
- Now run the required Maven goals in the project root path and use
neo
to deploy the packaged application to the remote Neo instance.mvn clean install /path/to/neo deploy --host HOST --account ACCOUNT --user USER --application firstapp --source application/target/firstapp-application.war /path/to/neo start --host HOST --account ACCOUNT --user USER --application firstapp
- You can check the status of your deployment with the
status
command:/path/to/neo status --host HOST --account ACCOUNT --user USER --application firstapp
- If you want to list all running applications use the
list-applications
command:/path/to/neo list-applications --host HOST --account ACCOUNT --user USER
- On the Neo website you will find the corresponding URL, where your application is reachable. It will be listed in the application’s details page and might follow the following pattern:
https://[application][subaccount].[host]/[application]-application/
from the values above.Hello world!
That’s it.
To find additional Neo commands, e.g. for stopping and undeploying applications, please take a look into the official lists of Neo Console Client Commands.
See the next tutorial in the series here: Step 3 with SAP Cloud SDK: HelloWorld on SCP CloudFoundry.
Troubleshooting
Force application shutdown
In case the Maven
scp:clean
goal does not shutdown the application background process, even after the second execution, we recommend terminating it by hand. First you need to detemine the process id by the public port. Then terminate the process.# Windows netstat -o -n -a | findstr 0.0:8003 taskkill /F /PID <PID>
# OSX lsof -i :8003 kill -9 <PID>
Windows PowerShell
If you are using Powershell on Windows, always put Maven arguments (supplied with
-D
) in quotes, for example:mvn archetype:generate "-DarchetypeGroupId=com.sap.cloud.s4hana.archetypes" "-DarchetypeArtifactId=scp-neo-javaee6" "-DarchetypeVersion=RELEASE"
Hi Alexander,
Thank you for such a great blog.
I am facing an issue in the deployment phase. When I execute the command "mvn scp:clean scp:push -pl application", I see the build is failed. Could you please help me in resolving this? Find the image below for reference.
Thanks,
Sankeerth
Hey Sankeerth,
Thank you for your interest in SAP S/4HANA Cloud SDK!
It seems like the local SCP Neo runtime is failing to install on your machine.
Regards
Alexander
Alexander,
Thank you very much for the response with solutions. Deleting files from ./application/scp/ worked for me.
In step Generate Project from Archetype I had to use quotation marks to make it run (powershell):
Hi Carsten, thanks for sharing the command line fix for PowerShell. For this program, we recommend encapsulating each parameter starting with “-D” into single or double quotes, see the troubleshooting paragraph at the end of the article. This is because “-” is a special character for PowerShell. Yet the proper (but unusual) way would be to escape it by using `
e.g.
Hi alexandar,
I was trying to execute the command:
During the second execution(mvn scp:clean scp:push -pl application) it is asking :Enter URL for destination ErpQueryendpoint: may I know what is the value to be applied here(yu have mentioned user name DUMMY and any value for password but not the url path) is http://localhost:8080/hello ?
Hey sathishkumar,
thank you for your message! Since we are not yet connecting to any ERP system during Step 2 of the tutorial, you can put any´dummy values for URL, username and password. As soon as you want to establish an actual connection to an ERP system, these values will become important.
If you experience any issues with your SCP Neo project, please find the troubleshooting section below in the blog post. Also please consider the delay for the local scp runtime to start up. This usually takes between one and two minutes. After that http://localhost:8080 should be responding.
I hope this helped you.
Best regards
Alexander
Hi Alexander,
Thank you,it's working now.
Hello Alexander Duemont ,
I am trying to deploy locally the application. Everything seems fine but when I try to reach localhost:8080, I get a 404.
Do you have an idea ? I've already tried to kill process but the issue still there.
Thank you.
Olivier
Hello Oliver,
"HTTP Error 404" shows us the web server is running, which is good.
For more recent versions of S/4HANA Cloud SDK, we changed the path on which the application is being hosted from "/" to "/[NAME]-application". So assuming your application is called "firstapp" you will find your website on http://localhost:8080/firstapp-application/hello
Best regards
Alexander
Brilliant ! Thank you Alexander Duemont
For your information, Neo deployment should be reached via URL below :
https://firstapp.[subaccount].[host]/firstapp-application/hello
After this step:
"Once the generation process is started, Maven will ask you for the usual module parameters:"
Hello Darren,
please confirm your Maven project parameters by entering " y " into the command prompt. Anything but " y[es] " will loop you through the properties again.
Best regards
Alexander
Hi Alexander,
I am using a trial account to go through this tutorial. I have gotten through the local deploy with no issues, and have deployed to Neo using the cli. The application itself deployed to Neo and started with no problem. However, when I try to visit the corresponding url, by clicking the link in the Application URLs section of the deployed application, I get a 401 Unauthorized page instead of the Hello World! that I expect. The application URL is of the form https://[appname][subaccount].[host]/[appname]-application/, but https://[appname][subaccount].[host]/[appname]-application/hello does the same thing, and https://[appname].[subaccount].[host]/[appname]-application/ gives me a Service Unavailable error.
Do you have any suggestions? Thanks very much.
The formatting got messed up; the 3 URLs are, in order:
Hi A Struble,
Can you please check out the “Default Trace” Log file on SCP Cockpit > Application > Monitoring > Logging ? You can download the log file and check for any exceptions during startup. Maybe the application cannot start.
By using the status command you can retrieve the URL to applicatio host:
It is https://[appname][subaccount].[host]/ (no dot in-between)
In the application overview screen on SCP Cockpit you can find the correct path: [appname]-application/
Best regards
Alexander
Hi Alexander,
I checked the logs and saw the errors "Failed to retrieve persistence properties, got response code 404" and "AuthnRequest cannot be send to the IDP." After some googling I was able to deduce that I needed to have the default settings in Security > Trust > Trust Management. I am now able to hit the URL successfully. Thanks for your help!
Hello Alexander,
I'm quite new to installing distributed development environments... so I have the first problem right after generating a project from archetype.
Please help, I don't have the slightest idea, what I'm doing wrong:
Kind regards
Nina
Hi Nina,
looks like proxy issues. Are you behind a corporate proxy?
If yes, you have to configure maven to deal with that:
https://maven.apache.org/guides/mini/guide-proxies.html
Kind regards,
Daniel
Hello,
thanks for the quick answer! No, this problem occurs with and without corporate proxy. Also when connecting without a proxy, the error is the same.
Configuring maven for proxys was done in step one, so it should not be a problem from the start.
Perhaps you have another idea?
Kind regards
Nina
Hello Nina,
I think Daniel is right with his assumption, that the proxy is causing you problems. You can find it repeatedly mentioned in your screenshot.
Please correct me if I'm wrong, but I assume you have the following proxy setting in your ~/.m2/settings.xml
This is what we suggested in Step 1, which you have followed.
Now, when your company proxy has a server host name different than "proxy", this configuration will fail as seen in your screenshot. Please consider "proxy" as a placeholder for any company proxy server host name. In case your computer does not require a proxy at all, please consider changing
to
Best regards
Alexander
Great! Thank you very much Alexander, I did overlook, that the word proxy had to be replaced!
Build complete. 🙂
Kind regards
Nina
Hi Expert,
I want to deploy and test this sample code on hana trial.
I am not comfortable to use command line to deploy on hana trail.
Can i deploy this sample code using Eclipse IDE without command line?
Thanks
If you have configured your Eclipse as shown here, that should be possible.
Please visit the documentation for more details.
I might also make sense to setup a continuous delivery pipeline as shown in our tutorial. This pipeline automatically deploys the application into your cloud foundry account.
Thanks a lot for your reply.
Hello Vipin,
I'm not sure about Eclipse, but I would recommend deploying the application on SCP Neo by using the SCP Cockpit. Just chose your file, and set the Java runtime to the latest "Java EE" version.
Best regards
Alexander
Thanks a lot for your reply.
Hi,
how can I set the log level for certain modules when I do local deployement?
Thanks and Regards,
Alex
Hi Alex,
The is a configuration file in application/scp/sdk-x.y.z/server/cofig_master/com.sap.js.logging
Copy both files to application/localServerContent/cofig_master/com.sap.js.logging
Afterwards you can adopt the file application/localServerContent/config_master/com.sap.js.logging/logging.cfg to change the log levels.
Best,
Daniel
Afterwards, execute mvn scp:push to redeploy your application.
Hello , someone can help me, after loading the app on the tomcat server, the tomcat manager works correctly, but when opening / firstapp gives code 500 error of Login Form
Hi Imadk,
do you use the local Neo runtime or a pure Tomcat server?
Using a pure tomcat is not supported for local Neo deployments.
Best regards
Sander
On running firstapp>mvn clean install, am getting an error as below:
Failed to execute goal com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:2.13.2:usage-analytics (default) on project firstapp-application: Execution default of goal com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:2.13.2:usage-analytics failed: Plugin com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:2.13.2 or one of its dependencies could not be resolved: Failed to collect dependencies at com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:jar:2.13.2 -> com.sap.cloud.s4hana.plugins:usage-analytics:jar:[2.13.2,): No versions available for com.sap.cloud.s4hana.plugins:usage-analytics:jar:[2.13.2,) within specified range -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :firstapp-application
Hi Suarshan,
thanks for your question, but please only ask them once, so that we don't have to copy our answers all over the place.
Have a look at https://stackoverflow.com/questions/53741371/projects-created-with-version-2-8-1-of-sdk-dont-build, there someone had the same problem and a solution was provided.
Greetings
Chris
Thanks Chris. This is resolved after starting from a clean slate again. Yes, first posted this on step 4 and then realized it belongs here under step 2.. Couldn't find a way to delete the post on step 4.. will take care of this now. Thanks again.
It shows a error when I used the command:mvn scp:clean scp:push -pl application

Could you help me solve the question?
Hi Jenson,
The first error message indicates a failing startup of the local Neo server runtime. This is unusual, and without further information we cannot help much. Please take a look into /application/scp/sdk-1.14.12/server/log/ljs_trace.log
Alternatively check the log files as described in the message: /application/scp/sdk-1.14.12/tools/log/
The second error message comes from the internally used Neo server plugin, it’s unable to create a linked directory without elevated user rights under Windows. You can safely ignore this message. Your application should work without being affected by this warning. Alternatively run the Maven command as administrator, however it’s not required.
Best regards
Alexander
HI Alexander
I have an issue about start my project on cloud.
Unable to start application firstsapapplication: Cannot start application 'firstsapapplication'; there is no compute unit quota for subaccount 'c0210650f'. You can: 1. Check the compute unit quotas of your subaccount 2. Configure compute unit size for the application with parameter --size
I found a solution on google.
neo set-quota –account c0210650f –user XXXXXXXX –host cn1.hana.ondemand.com -–amount lite:1
1.do you know how to find right user(XXXXX)? is this my login user? or some technical name or some id in this cloud system?
2.after tab this command. i need to enter my login password, but always Wrong credentials. Enter correct user name and password.
can you help? thanks
Dear Fei Zhu,
(1) It corresponds to your login user
(2) You have to provide your correct credentials for the SCP Neo Environment
Thanks
Marco
Hi Alexander,
when deploying to the local hana runtime: the login comes up but the app is not accessible (it stays on the login page does not matter what url i give).
Its also very easy to reproduce - assume myapp is the app name
mvn archetype:generate -DarchetypeGroupId=com.sap.cloud.sdk.archetypes -DarchetypeArtifactId=scp-neo-javaee7 -DarchetypeVersion=RELEASE
mvn clean install
mvn scp:clean scp:push -pl application
now navigate to http://localhost:8080/application-myapp
login will come up, enter test / test but nothing happens.
If I deploy the .war on a cloud account it works perfectly. It just does not work on local runtime.
Let's keep the discussion here since it's easier to communicate: https://answers.sap.com/questions/13195190/sap-hana-cloud-platform-local-runtime-does-not-pro.html