Technical Articles
Step 3 with SAP Cloud SDK: HelloWorld on SCP CloudFoundry
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 SAP Cloud Platform Cloud Foundry using the SAP Cloud SDK. If you want to follow this tutorial, we highly recommend checking out the first part of this blog series.
Note: This post is part of a series. For a complete overview visit the SAP Cloud SDK Overview.
Goal of this blog post
This tutorial will cover your first steps when developing applications for SCP CloudFoundry using the SAP Cloud SDK. More specifically, we will cover the following steps:
- Create an account for SCP CloudFoundry and setup the CloudFoundry command line interface for deploying and managing CloudFoundry applications.
- Generate your first project using the SAP Cloud SDK Maven archetype and understand its structure.
- Deploy your first application to SCP CloudFoundry.
The screenshot below shows the final result of this tutorial.
Setup for CloudFoundry
In order to deploy applications to SCP CloudFoundry, you need to create a free trial account. You can create your account by visiting https://cloudplatform.sap.com/try.html
After creating your account and activating it via email, you can log in to your personal cloud cockpit. For your first visit, it should look like this:
Now click the “Home” button in the upper navigation bar and then click “Start Cloud Foundry Trial”.
After selecting your region, your account will be automatically setup for development with CloudFoundry.
Now that your account is activated and configured, you will need the CloudFoundry command line interface (cf
CLI) to deploy and manage your CloudFoundry applications.
To install cf
CLI, you can either grab the latest release on the official release page or use your favorite package manager.
In order to deploy applications on SAP CloudFoundry we need to provide cf
CLI with an API endpoint. The API endpoint depends on the region you chose for your account:
- for EU: https://api.cf.eu10.hana.ondemand.com
- for US EAST: https://api.cf.us10.hana.ondemand.com
- for US WEST (beta): https://api.cf.us20.hana.ondemand.com
Now enter the following commands (in this case for the EU region):
cf api https://api.cf.eu10.hana.ondemand.com
cf login
The cf
CLI will ask you for your mail and your password. After entering these, you should be successfully logged in!
Generate Project from Archetype
To generate your first project from the Maven archetype, run the following command:
mvn archetype:generate -DarchetypeGroupId=com.sap.cloud.s4hana.archetypes -DarchetypeArtifactId=scp-cf-tomee -DarchetypeVersion=RELEASE
During the generation process, Maven will require additional parameters to form your project:
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 ) |
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. |
uniqueHostname |
(versions 1.0.0 – 1.8.0) An unique identifier to determine your initial project URL on CloudFoundry. This value must be unique across your CloudFoundry region, but it can easily be changed later on. We recommend Application Name + some random number, e.g.: |
After providing these values, Maven will generate your project from the archetype.
Note: We have created here an application which is based on the TomEE runtime which is Java EE 6 compliant OpenSource runtime that is available in the Cloud Foundry platform if you aim at a Java EE application. You may also initialize the project with SpringBoot (artifactId: scp-cf-spring) or on a pure Tomcat container (artifactId: scp-cf-tomcat). Our tutorial series will be primarily based on the TomEE runtime, we may cover flavors in SpringBoot or Tomcat later in this blog. Nonetheless, the SAP Cloud SDK is compatible with these popular runtimes too.
Understand the project structure and its artifacts
Now you can open your favorite IDE and import the project as ‘Maven Project’. After importing the project into your IDE, the project structure should 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
src/test/java Additional test classes. src/test/resources Additional resources for attached test modules. 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. manifest.yml
is the deployment descriptor for CloudFoundry.
We will take a closer look at this file once we deploy the 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 structure of the project, let’s take a closer look at the HelloWorldServlet
.
package com.sap.cloud.sdk.tutorial;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
@WebServlet("/hello")
public class HelloWorldServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.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!”.
Note: The application code runs seamlessly in SAP Cloud Platform, Neo as well as SAP Cloud Platform, Cloud Foundry. The SAP Cloud SDK is compatible with both versions and provides mechanisms to seamlessly transfer code between both environments.
Deployment
In order to deploy the application, we first need to assemble our project into a deployable artifact – a .war
file. Open your command line and change into the firstapp
directory, the root directory of your project and run the following command:
cd /path/to/firstapp
mvn clean package
This tells maven to remove any files from previous assemblies (clean
) and to assemble our project (package
). The project is setup so that Maven automatically runs our unit and integration tests for us. After running the command there should be a directory target
inside of the application
directory, containing a file called firstapp-application.war
. This is the file that we will deploy to Cloud Foundry (or locally).
Deploy to Cloud Foundry
Now the previously mentioned manifest.yml
comes into play – it’s the deployment descriptor used by Cloud Foundry. A default version has been generated by the archetype. In order have enough memory available also for later steps of this tutorial series, please make sure to have the instance memory set to 1024 MB. Also the environment variable JBP_CONFIG_SAPJVM_MEMORY_SIZES
should be declared as shown below.
---
applications:
- name: firstapp
memory: 1024M
host: firstapp-D123456
# random-route: true # used instead of "host"
path: application/target/firstapp-application.war
buildpack: sap_java_buildpack
env:
TARGET_RUNTIME: tomee
JBP_CONFIG_SAPJVM_MEMORY_SIZES: "metaspace:96m.."
The manifest contains a list of applications that will be deployed to Cloud Foundry. In this example we only have one application, firstapp
, with the following parameters:
name | This is the identifier of your application within your organization and your space in SCP CloudFoundry. |
memory | The amount of memory allocated for your application. |
host | Determines the URL of your application after deploying it. |
random-route | Set to true if you want the application instance to be hosted to a random route. This ensures that the URL of your application is unique and as such avoids name collisions. The random route is created once for the application instance and will be kept even after restart. Please note: This will only work, if no host setting is provided. |
path | The relative path to the artifact to be deployed. |
buildpack | A buildpack is what CloudFoundry uses to build and deploy your application. Since this is a Java application, we use the sap_java_buildpack . |
env | Here we can provide additional application specific environment variables. For example we specify that we want to use a TomEE container as our target runtime. |
Now you can deploy the application by entering the following command:
cf push
cf push
is the command used to deploy applications. The -f
flag provides cf
CLI with the deployment descriptor.
Hint: If you omit the
-f
flag,cf
CLI will check whether there is a file namedmanifest.yml
in the current directory. If so,cf
CLI will use this file as deployment descriptor. Else, it will fail.
After the deployment is finished, cf
CLI’s output should look like this:
Now we can visit the application under its corresponding URL as it is shown in the output above. Take the value from “urls: ...
” and append the “/hello
” path:
Hello world!
That’s it.
Run the Application on a Local Server
Since version 1.1.1 of the SAP Cloud SDK, the generated projects can also be run locally out-of-the-box. To do so, first assemble the project using the mvn clean package
command (see above).
Then, run the following commands to start the local server:
cd application
mvn tomee:run
Visit http://localhost:8080/hello on your local machine to view the response of our application. You can stop the server by pressing Ctrl + C
.
Now you have a strong basis for developing your own cloud application for SCP Cloud Foundry using the SAP Cloud SDK. Stay tuned for upcoming blog posts about more advanced usages of the SAP Cloud SDK.
See the next tutorial in the series here: Step 4 with SAP Cloud SDK: Calling an OData Service.
Troubleshooting
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-cf-tomee" "-DarchetypeVersion=RELEASE"
Awesome walkthrough, Alexander. Thanks!
Cheers,
Simen
Hi Alexander,
I am stuck with the below step:
Now enter the following commands (in this case for the EU region):
prior to this i have downloaded and executed the files cf-cli_6.33.1_winx64 and cf-cli_edge_winx64 ( CloudFoundry command line interface (
cf
CLI) ) ,the cmd window mode just popes up and closed after executing both .exe files,then I tried to copy past the file in Cmd as below.Could you please guide me where to execute those 2 line of commands?Thank you.
Regards,
Sathishkumar.V
Hi Sathishkumar,
have you used the binaries or the installer?
You should download the installer from the following webpage (select Windows):
https://github.com/cloudfoundry/cli/releases
Inside the zip you will a file called cf_installer.exe. Executing this file should guide you through the installation process.
The steps are also described here: https://docs.cloudfoundry.org/cf-cli/install-go-cli.html#windows
Best Regards,
Daniel
Hi Daniel,
Thanks for your prompt reply,
I have now used https://docs.cloudfoundry.org/cf-cli/install-go-cli.html#windows and this file has worked I have now deployed the application.
Hi Alexander,
I am trying to push the application, but getting the below error.
C:\Program Files\Cloud Foundry>cf.exe push "D:\SAP Cloud SDK\firstapp"
Pushing app D:\SAP Cloud SDK\firstapp to org P2001738490trial_trial / space dev as swatiibaluni2492@gmail.com...
Getting app info...
Updating app with these attributes...
name: D:\SAP Cloud SDK\firstapp
path: C:\Program Files\Cloud Foundry
disk quota: 1G
health check type: port
instances: 1
memory: 1G
stack: cflinuxfs3
routes:
dsap-cloud-sdkfirstapp.cfapps.eu10.hana.ondemand.com
Updating app D:\SAP Cloud SDK\firstapp...
Mapping routes...
Comparing local files to remote cache...
Packaging files to upload...
Uploading files...
760.36 KiB / 760.36 KiB [=================================================================================] 100.00% 1s
Waiting for API to complete processing files...
Staging app and tracing logs...
Downloading sap_java_buildpack...
Downloading dotnet_core_buildpack...
Downloading binary_buildpack...
Downloading r_buildpack...
Downloading staticfile_buildpack...
Downloaded dotnet_core_buildpack
Downloading ruby_buildpack...
Downloaded r_buildpack
Downloading sap_java_buildpack_1_18...
Downloaded sap_java_buildpack
Downloading java_buildpack...
Downloaded binary_buildpack
Downloading sap_java_buildpack_1_17...
Downloaded staticfile_buildpack
Downloading go_buildpack...
Downloaded ruby_buildpack
Downloading nodejs_buildpack...
Downloaded java_buildpack
Downloading python_buildpack...
Downloaded sap_java_buildpack_1_18
Downloading php_buildpack...
Downloaded sap_java_buildpack_1_17
Downloading nginx_buildpack...
Downloaded go_buildpack
Downloading sap_java_buildpack_1_16...
Downloaded nodejs_buildpack
Downloaded php_buildpack
Downloaded nginx_buildpack
Downloaded sap_java_buildpack_1_16
Downloaded python_buildpack
Cell 0d7f673b-177d-442d-9644-17acf5671b63 creating container for instance c1de4306-fd50-488e-be45-cb8ed3acbdc9
Cell 0d7f673b-177d-442d-9644-17acf5671b63 successfully created container for instance c1de4306-fd50-488e-be45-cb8ed3acbdc9
Downloading app package...
Downloaded app package (82.5M)
None of the buildpacks detected a compatible application
Exit status 222
Cell 0d7f673b-177d-442d-9644-17acf5671b63 stopping instance c1de4306-fd50-488e-be45-cb8ed3acbdc9
Cell 0d7f673b-177d-442d-9644-17acf5671b63 destroying container for instance c1de4306-fd50-488e-be45-cb8ed3acbdc9
Cell 0d7f673b-177d-442d-9644-17acf5671b63 successfully destroyed container for instance c1de4306-fd50-488e-be45-cb8ed3acbdc9
Error staging application: An app was not successfully detected by any available buildpack
TIP: Use 'cf.exe buildpacks' to see a list of supported buildpacks.
FAILED
Could you please help us in resolving this error?
Regards
Swati Pant
Hi Alexander,
Trying to run the application on a Local Server using mvn tomee:run leads to the following error:
[ERROR] No plugin found for prefix 'tomee' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local ...]), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException: No plugin found for prefix 'tomee' in the current project and in the plugin groups
Any ideas how to fix it?
Best regards
Oliver
Hi Oliver,
Please run "mvn tomee:run" from within the "./application" directory. Alternatively you can run "mvn tomee:run -f application" from your project root.
If this does not solve your issue, please let us know SDK version number and consider attaching the POM files "./pom.xml" and "./application/pom.xml".
Best regards
Alexander
Hi Alexander,
Please also explain how to run the application locally in case using spring which leads to an jar instead of war.
Thanks in advance.
Best regards
Oliver
Hi Oliver,
Applications, built by using the Spring archetype, can be run locally by “mvn spring-boot:run” within the “application” directory. Alternatively you can run “mvn tomee:run -f application” from your project root.
Best regards
Alexander
Hi Alexandra,
I have done all the setups to build the project firstapp however my manifest.yml did not created automatically while I am trying to push the project it is getting failed is there anything I am missing any step.
Regards
Hi Amit,
the manifest.yml should be created when you execute the "mvn archetype:generate ..." command at the beginning of the guide. Can you please check this by setting up a new project in an empty directory?
Also, regarding the push problem, can you please provide the output of the "cf push" command? That way we can probably pin point the issue.
Best regards
Chris
Hi Christoph,
Thanks for your prompt reply please find the below cf push log
Pushing app to org S0019145314trial_trial / space dev as amit.c.kulkarni..
Incorrect usage: The push command requires an app name. The app name can be supplied as an argument or with a manifest.yml file.
FAILED
NAME:
push - Push a new app or sync changes to an existing app
USAGE:
cf push APP_NAME [-b BUILDPACK_NAME] [-c COMMAND] [-f MANIFEST_PATH | --no-manifest] [--no-start]
[-i NUM_INSTANCES] [-k DISK] [-m MEMORY] [-p PATH] [-s STACK] [-t HEALTH_TIMEOUT] [-u (process | port | http)]
[--no-route | --random-route | --hostname HOST | --no-hostname] [-d DOMAIN] [--route-path ROUTE_PATH] [--var KEY=VALUE] [--vars-file VARS_FILE_PATH]...
cf push APP_NAME --docker-image [REGISTRY_HOST:PORT/]IMAGE[:TAG] [--docker-username USERNAME]
[-c COMMAND] [-f MANIFEST_PATH | --no-manifest] [--no-start]
[-i NUM_INSTANCES] [-k DISK] [-m MEMORY] [-t HEALTH_TIMEOUT] [-u (process | port | http)]
[--no-route | --random-route | --hostname HOST | --no-hostname] [-d DOMAIN] [--route-path ROUTE_PATH] [--var KEY=VALUE] [--vars-file VARS_FILE_PATH]...
cf push APP_NAME --droplet DROPLET_PATH
[-c COMMAND] [-f MANIFEST_PATH | --no-manifest] [--no-start]
[-i NUM_INSTANCES] [-k DISK] [-m MEMORY] [-t HEALTH_TIMEOUT] [-u (process | port | http)]
[--no-route | --random-route | --hostname HOST | --no-hostname] [-d DOMAIN] [--route-path ROUTE_PATH] [--var KEY=VALUE] [--vars-file VARS_FILE_PATH]...
cf push -f MANIFEST_WITH_MULTIPLE_APPS_PATH [APP_NAME] [--no-start]
ALIAS:
p
OPTIONS:
-b Custom buildpack by name (e.g. my-buildpack) or Git URL (e.g. 'https://github.com/cloudfoundry/java-buildpack.git') or Git URL with a branch or tag (e.g. 'https://github.com/cloudfoundry/java-buildpack.git#v3.3.0' for 'v3.3.0' tag). To use built-in buildpacks only, specify 'default' or 'null'
-c Startup command, set to null to reset to default start command
-d Domain (e.g. example.com)
--docker-image, -o Docker-image to be used (e.g. user/docker-image-name)
--docker-username Repository username; used with password from environment variable CF_DOCKER_PASSWORD
--droplet Path to a tgz file with a pre-staged app
-f Path to manifest
--health-check-type, -u Application health check type (Default: 'port', 'none' accepted for 'process', 'http' implies endpoint '/')
--hostname, -n Hostname (e.g. my-subdomain)
-i Number of instances
-k Disk limit (e.g. 256M, 1024M, 1G)
-m Memory limit (e.g. 256M, 1024M, 1G)
--no-hostname Map the root domain to this app
--no-manifest Ignore manifest file
--no-route Do not map a route to this app and remove routes from previous pushes of this app
--no-start Do not start an app after pushing
-p Path to app directory or to a zip file of the contents of the app directory
--random-route Create a random route for this app
--route-path Path for the route
-s Stack to use (a stack is a pre-built file system, including an operating system, that can run apps)
--vars-file Path to a variable substitution file for manifest; can specify multiple times
--var Variable key value pair for variable substitution, (e.g., name=app1); can specify multiple times
-t Time (in seconds) allowed to elapse between starting up an app and the first healthy response from the app
ENVIRONMENT:
CF_STAGING_TIMEOUT=15 Max wait time for buildpack staging, in minutes
CF_STARTUP_TIMEOUT=5 Max wait time for app instance startup, in minutes
CF_DOCKER_PASSWORD= Password used for private docker repository
SEE ALSO:
apps, create-app-manifest, logs, ssh, start
also we have raised the SAP ticket and got the reply there are only specific BAPI's only we can we are following these series of blog to complete our POC to call
BAPI_SALESORDER_CREATEFROMDAT2
BAPI_SALESORDER_SIMULATE
Hi Amit,
yes BAPI_SALESORDER_SIMULATE was white listed to be called from SAP onPremise systems via the cloud connector into the S/4HANA Cloud.
But this whitelisting does not directly enable the BAPI to be used as described in the blog post.
At some point the blog post mentions the list of BAPIs that were enabled for cloud SDK.
We do not intend to enable BAPI_SALESORDER_SIMULATE to be used in cloud SDK, as we want to cover the functionality of simulating the creation of a sales order in an synchronous call by providing an OData API Service.
Regards,
Hi Amit,
this output is to be expected if no manifest.yml could be found in your current directory.
Therefore, can you please verify whether the "mvn archetype:generate ...", as specified in the blog above, creates a manifest.yml file on your system?
Best regards
Chris
Hi Chris,
Thanks for your reply. I recreated the project and got mainfest file.
Regards,
Hi, with command
cf push
I get all positive cf responses until
Creating app firstapp...
Mapping routes...
You have exceeded the total routes for your organization's quota.
FAILED
What do I have to do in my CF subaccount to fix that? Or is the issue somewhere else?
I was able to find an answer myself after all: https://answers.sap.com/questions/392127/quota-plans-error-in-sap-cloud-platform-cloud-foun.html
Hi,
generating my first project from the Maven archetype with the below commnet:
mvn archetype:generate -DarchetypeGroupId=com.sap.cloud.s4hana.archetypes -DarchetypeArtifactId=scp-cf-tomee -DarchetypeVersion=LATEST
I am getting the following error message:
Downloading from central: https://repo.maven.apache.org/maven2/com/sap/cloud/s4hana/archetypes/scp-cf-tomee/maven-metadata.xml
[WARNING] Could not transfer metadata com.sap.cloud.s4hana.archetypes:scp-cf-tomee/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): TransferFailedException
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.651 s
[INFO] Finished at: 2018-11-19T14:42:06+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate (default-cli) on project standalone-pom: The desired archetype does not exist (com.sap.cloud.s4hana.archetypes:scp-cf-tomee:LATEST) -> [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/MojoFailureException
Regards
Artur
Hi Artur,
could you rerun the command with the -e flag and report the results please?
Best regards,
Dennis
Hi Dennis,
the result is below:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate (default-cli) on project standalone-pom: The desired archetype does not exist (com.sap.cloud.s4hana.archetypes:scp-cf-tomee:LATEST) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate (default-cli) on project standalone-pom: The desired archetype does not exist (com.sap.cloud.s4hana.archetypes:scp-cf-tomee:LATEST)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: The desired archetype does not exist (com.sap.cloud.s4hana.archetypes:scp-cf-tomee:LATEST)
at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execute (CreateProjectFromArchetypeMojo.java:216)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.archetype.exception.UnknownArchetype: The desired archetype does not exist (com.sap.cloud.s4hana.archetypes:scp-cf-tomee:LATEST)
at org.apache.maven.archetype.ui.generation.DefaultArchetypeGenerationConfigurator.configureArchetype (DefaultArchetypeGenerationConfigurator.java:125)
at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execute (CreateProjectFromArchetypeMojo.java:200)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[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/MojoFailureException
Regards
Artur
Hi,
yes I did it as described https://blogs.sap.com/2017/05/15/step-1-with-sap-s4hana-cloud-sdk-set-up/
now I have removed the setting.xml file and is working 🙂
Regards
Artur
Hi Alexander,
thanks for the tutorial.
I followed your instructions to the point where i am going to import the project created with the maven archetype into eclipse.
During the import of the project i get the following error:
"No marketplace entries found to handle s4sdk-maven-plugin:2.11.1:usage-analytics in Eclipse"
It's caused by the following section in the pom.xml file of the application submodule
<plugin>
<groupId>com.sap.cloud.s4hana.plugins</groupId>
<artifactId>s4sdk-maven-plugin</artifactId>
<version>2.11.1</version>
<executions>
<execution>
<goals>
<goal>usage-analytics</goal>
</goals>
<configuration>
<skipUsageAnalytics>false</skipUsageAnalytics>
<generateSalt>true</generateSalt>
<!--
Note: A random salt is auto-generated once the project is built for the first time.
Please keep the generated salt in the POM file, for example, when pushing to git.
To learn more, visit: https://blogs.sap.com/2018/10/23/usage-analytics-s4sdk/
-->
<salt />
</configuration>
</execution>
</executions>
</plugin>
do you have an idea what's wrong here?
best regards,
Martin
Hi Martin,
I was able to reproduce this issue. We will add this to our planned fixes.
For now, you can mark this as ignored in Eclipse.
Thanks for reporting this!
Best regards
Sander
I had an issue about :s4sdk-maven-plugin:2.14.0:usage-analytics as well trying to do mvn clean command on the maven archetype.
I managed to get the build success by chosing archetype version 2.7.0 instead of LATEST (which is 2.14.0)
find below the error I encountered :
C:\devS4SDK\firstapp>mvn clean package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] firstapp - Root [pom]
[INFO] firstapp - Application [war]
[INFO] firstapp - Unit Tests [jar]
[INFO] firstapp - Integration Tests [jar]
[INFO]
[INFO] ----------------< com.sap.cloud.sdk.tutorial:firstapp >-----------------
[INFO] Building firstapp - Root 1.0-SNAPSHOT [1/4]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ firstapp ---
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (SAP S/4HANA Cloud SDK Project Structure Checks) @ firstapp ---
[INFO]
[INFO] ----------< com.sap.cloud.sdk.tutorial:firstapp-application >-----------
[INFO] Building firstapp - Application 1.0-SNAPSHOT [2/4]
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ firstapp-application ---
[INFO] Deleting C:\devS4SDK\firstapp\application\target
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (SAP S/4HANA Cloud SDK Project Structure Checks) @ firstapp-application ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ firstapp-application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ firstapp-application ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\devS4SDK\firstapp\application\target\classes
[INFO]
[INFO] --- s4sdk-maven-plugin:2.14.0:usage-analytics (default) @ firstapp-application ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for firstapp - Root 1.0-SNAPSHOT:
[INFO]
[INFO] firstapp - Root .................................... SUCCESS [ 0.741 s]
[INFO] firstapp - Application ............................. FAILURE [ 2.986 s]
[INFO] firstapp - Unit Tests .............................. SKIPPED
[INFO] firstapp - Integration Tests ....................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.161 s
[INFO] Finished at: 2019-04-12T13:50:31+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:2.14.0:usage-analytics (default) on project firstapp-application: Execution default of goal com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:2.14.0:usage-analytics failed: Plugin com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:2.14.0 or one of its dependencies could not be resolved: Failed to collect dependencies at com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:jar:2.14.0 -> com.sap.cloud.s4hana.plugins:usage-analytics:jar:[2.14.0,): No versions available for com.sap.cloud.s4hana.plugins:usage-analytics:jar:[2.14.0,) 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
C:\devS4SDK\firstapp>mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] firstapp - Root [pom]
[INFO] firstapp - Application [war]
[INFO] firstapp - Unit Tests [jar]
[INFO] firstapp - Integration Tests [jar]
[INFO]
[INFO] ----------------< com.sap.cloud.sdk.tutorial:firstapp >-----------------
[INFO] Building firstapp - Root 1.0-SNAPSHOT [1/4]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ firstapp ---
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (SAP S/4HANA Cloud SDK Project Structure Checks) @ firstapp ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ firstapp ---
[INFO] Installing C:\devS4SDK\firstapp\pom.xml to C:\Users\i351331\.m2\repository\com\sap\cloud\sdk\tutorial\firstapp\1.0-SNAPSHOT\firstapp-1.0-SNAPSHOT.pom
[INFO]
[INFO] ----------< com.sap.cloud.sdk.tutorial:firstapp-application >-----------
[INFO] Building firstapp - Application 1.0-SNAPSHOT [2/4]
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ firstapp-application ---
[INFO] Deleting C:\devS4SDK\firstapp\application\target
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (SAP S/4HANA Cloud SDK Project Structure Checks) @ firstapp-application ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ firstapp-application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ firstapp-application ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\devS4SDK\firstapp\application\target\classes
[INFO]
[INFO] --- s4sdk-maven-plugin:2.14.0:usage-analytics (default) @ firstapp-application ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for firstapp - Root 1.0-SNAPSHOT:
[INFO]
[INFO] firstapp - Root .................................... SUCCESS [ 0.954 s]
[INFO] firstapp - Application ............................. FAILURE [ 3.340 s]
[INFO] firstapp - Unit Tests .............................. SKIPPED
[INFO] firstapp - Integration Tests ....................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.717 s
[INFO] Finished at: 2019-04-12T13:52:35+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:2.14.0:usage-analytics (default) on project firstapp-application: Execution default of goal com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:2.14.0:usage-analytics failed: Plugin com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:2.14.0 or one of its dependencies could not be resolved: Failed to collect dependencies at com.sap.cloud.s4hana.plugins:s4sdk-maven-plugin:jar:2.14.0 -> com.sap.cloud.s4hana.plugins:usage-analytics:jar:[2.14.0,): No versions available for com.sap.cloud.s4hana.plugins:usage-analytics:jar:[2.14.0,) 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,
first of all thanks for the tutorial!
I had a smaller issue with the manifest.yml. During cf push it complains about the following lines
buildpacks:
-sap_java_buildpack
which has to be replaced by
buildpack: sap_java_buildpack
Could the archetype be adapted accordingly or did I miss something?
Thanks and Best Regards, Christoph
Hi Christoph,
according to the cloud foundry manifest documentation the buildpack attribute is deprecated and buildpacks should be used instead: https://docs.cloudfoundry.org/devguide/deploy-apps/manifest-attributes.html#buildpack-deprecated
Which version of the cf CLI client are you using? (You can check this via cf --version on your console).
Greetings
Chris
Hi Alexander,
I have a strange issue. I generated sample aplication using maven archetype that you provided and deployed - that part works. I added new methods to the servlet:
I am using Postman to send POST and PUT http request. My problem is that all requests are sent to doGet. In the logs I see infromation that I am sending GET /hello which is not true. Do you by any chance came across such error? Do you have an idea what configuration can cause http method change?
I would appreciate any help.
Hi Kamil,
Indeed this sounds strange. Do you happen to use an approuter layer above your application? If I remember correctly, it allows for limiting HTTP methods.
Kind regards
Alexander
Hi Kamil,
Since this unusual problem came up again, I want to ask:
Were you able to resolve this issue by chance?
Kind regards
Alexander
Hi Alexander,
The problem exists when you try to call service using http. When you use https the problem dissapears.
Best Regards,
Kamil Warcaba