From d59ee76778b0668186d34c64d9c1ea128fd34aab Mon Sep 17 00:00:00 2001 From: Vladimir Mikhaylenko Date: Tue, 12 Aug 2025 13:12:38 +0200 Subject: [PATCH 1/7] Add additional trick for mvn cds:watch --- java/developing-applications/running.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/java/developing-applications/running.md b/java/developing-applications/running.md index 6307e00e05..be7f79a968 100644 --- a/java/developing-applications/running.md +++ b/java/developing-applications/running.md @@ -89,6 +89,20 @@ When you add the [Spring Boot Devtools](https://docs.spring.io/spring-boot/docs/ On Windows, the `watch` goal only works if the Spring Boot Devtools are enabled. ::: +You can customize the goals that are executed when the application is restarted after the change. + +Use the following command to execute the CDS build and code generator: + +```sh +mvn cds:watch -Dgoals=cds,generate +``` + +Or, if you want even faster feedback loop when doing Java-only changes, use: + +```sh +mvn cds:watch -Dgoals=generate +``` + ### CDS Auto-Build If you want to have the comfort of an automated CDS build like with the `watch` goal but want to control your CAP Java application from within the IDE, you can use the `auto-build` goal. This goal reacts on any CDS file change and performs a rebuild of your applications's CDS model. However, no CAP Java application is started by the goal. This doesn't depend on Spring Boot Devtools support. From bdcd534287bca7b7d944986bc1edea258d01cfe8 Mon Sep 17 00:00:00 2001 From: Vladimir Mikhaylenko Date: Tue, 12 Aug 2025 15:06:28 +0200 Subject: [PATCH 2/7] Rewrite --- java/developing-applications/running.md | 120 ++++++++++++------------ 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/java/developing-applications/running.md b/java/developing-applications/running.md index be7f79a968..c477031963 100644 --- a/java/developing-applications/running.md +++ b/java/developing-applications/running.md @@ -13,40 +13,20 @@ uacp: Used as link target from Help Portal at https://help.sap.com/products/BTP/ } -## Spring Boot Devtools -You can speed up your development turnaround by adding the [Spring Boot Devtools](https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools) dependency to your CAP Java application. Just add this dependency to the `pom.xml` of your `srv` module: - -```xml - - org.springframework.boot - spring-boot-devtools - -``` - -Once this is added, you can use the restart capabilities of the Spring Boot Devtools while developing your application in your favorite Java IDE. Any change triggers an automatic application context reload without the need to manually restart the complete application. Besides being a lot faster than a complete restart this also eliminates manual steps. The application context reload is triggered by any file change on the application's classpath: - -* Java classes (for example, custom handlers) -* Anything inside src/main/resources - * Configuration files (for example, _application.yaml_) - * Artifacts generated from CDS (schema.sql, CSN, EDMX) - * Any other static resource -::: warning Restart for changed Java classes -Spring Boot Devtools only detects changes to .class files. You need to enable the *automatic build* feature in your IDE which detects source file changes and rebuilds the .class file. If not, you have to manually rebuild your project to restart your CAP Java application. -::: +During development, you often have to perform the same steps to test the changes in the CDS model: -### CDS Build +1. Modify your CDS model. +1. Build and run your application. +1. Test your changes. -The Spring Boot Devtools have no knowledge of any CDS tooling or the CAP Java runtime. Thus, they can't trigger a CDS build if there are changes in the CDS source files. For more information, please check the [Local Development Support](#local-development-support) section. +CAP offers you several options to run your applications locally and enable quick turnarounds. This article covers only the applications based on Spring Boot. -::: tip -CDS builds in particular change numerous resources in your project. To have a smooth experience, define a [trigger file](https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools.restart.triggerfile) and [use `auto-build` goal](#cds-auto-build) of the CDS Maven plugin started from the command line. +:::tip +The fastest way of development in CAP is an automated testing. See [Service Layer Testing](../developing-applications/testing#service-layer-testing) ::: - -## Local Development Support - -### Use `cds` Prefix Everywhere +## Use `cds` Prefix Everywhere To use the `cds` prefix of the `cds-maven-plugin` from everywhere, add the plugin group `com.sap.cds` to your local `~/.m2/settings.xml`: @@ -58,68 +38,92 @@ To use the `cds` prefix of the `cds-maven-plugin` from everywhere, add the plugi This uses the [Maven plugin prefix resolution](https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html) feature. This Maven feature allows you to use only the `cds` prefix of the `cds-maven-plugin` to execute goals of this plugin. For example, instead of `mvn com.sap.cds:cds-maven-plugin:watch` you can use the shorter variant `mvn cds:watch` to run the `watch` goal of the `cds-maven-plugin`. -### CDS Watch -In addition to the previously mentioned build tasks, the CDS Maven plugin can also support the local development of your CAP Java application. During development, you often have to perform the same steps to test the changes in the CDS model: +## Run Java application in your IDE -1. Modify your CDS model. -1. Build and run your application. -1. Test your changes. +The fastest way to run the CAP Java application is with the IDE that can run and debug Java applications. CAP applications, however, require own build tools to compile CDS models. -To automate and accelerate these steps, the `cds-maven-plugin` offers the goal `watch`, which can be executed from the command line by using Maven: +The `auto-build` goal of the CDS Maven Plugin reacts on any CDS file change and performs a rebuild of your application CDS model. When you restart the application in the IDE or re-run tests, the updated model is picked up your application. + +Run this in your terminal and leave it open: ```sh -mvn cds:watch +mvn cds:auto-build ``` + :::details Other options if you've not configured the plugin group ```sh # from your root directory -mvn com.sap.cds:cds-maven-plugin:watch +mvn com.sap.cds:cds-maven-plugin:auto-build # or your srv/ folder cd srv -mvn cds:watch +mvn cds:auto-build ``` ::: -It builds and starts the application and looks for changes in the CDS model. If you change the CDS model, these are recognized and a restart of the application is initiated to make the changes effective. - -The `watch` goal uses the `spring-boot-maven-plugin` internally to start the application with the goal `run` (this also includes a CDS build). Therefore, it's required that the application is a Spring Boot application and that you execute the `watch` goal within your service module folder. -When you add the [Spring Boot Devtools](https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools) to your project, the `watch` goal can take advantage of the reload mechanism. In case your application doesn't use the Spring Boot Devtools the `watch` goal performs a complete restart of the Spring Boot application after CDS model changes. As the application context reload is always faster than a complete restart the approach using the Spring Boot Devtools is the preferred approach. +Use your IDE to run or debug your application. -::: warning -On Windows, the `watch` goal only works if the Spring Boot Devtools are enabled. +::: tip +If the Spring Boot Devtools configuration of your CAP Java application defines a [trigger file](https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools.restart.triggerfile), the `auto-build` can detect this and touch the trigger file in case of any file change. The same applies to the `watch` goal. ::: -You can customize the goals that are executed when the application is restarted after the change. +## Run Java application with CDS Watch + +CDS Maven plugin also provide the goal `watch` that does CDS build and can start your application. -Use the following command to execute the CDS build and code generator: +Run this in your terminal: ```sh -mvn cds:watch -Dgoals=cds,generate +mvn cds:watch ``` -Or, if you want even faster feedback loop when doing Java-only changes, use: +The `watch` goal uses the `spring-boot-maven-plugin` internally to start the application with the goal `run` (this also includes a CDS build). +When you add the [Spring Boot Devtools](../developing-applications/running#spring-boot-devtools) to your project, the `watch` goal can take advantage of the reload mechanism. +In case your application doesn't use the Spring Boot Devtools, the `watch` goal performs a complete restart of the application after CDS model changes, which is slower. -```sh -mvn cds:watch -Dgoals=generate -``` +::: warning +On Windows, the `watch` goal only works if the Spring Boot Devtools are enabled. +::: -### CDS Auto-Build +You can customize the goals that are executed when the application is restarted after the change to get even faster feedback: -If you want to have the comfort of an automated CDS build like with the `watch` goal but want to control your CAP Java application from within the IDE, you can use the `auto-build` goal. This goal reacts on any CDS file change and performs a rebuild of your applications's CDS model. However, no CAP Java application is started by the goal. This doesn't depend on Spring Boot Devtools support. +- Use the following command to execute the CDS build and code generator: -::: tip -If the Spring Boot Devtools configuration of your CAP Java application defines a [trigger file](https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools.restart.triggerfile), the `auto-build` can detect this and touch the trigger file in case of any file change. The same applies to the `watch` goal. + ```sh + mvn cds:watch -Dgoals=cds,generate + ``` + +- If you want even faster feedback loop when you change CDS models and do not need code generator, use this: + + ```sh + mvn cds:watch -Dgoals=cds + ``` + +::: warning Restart for changed Java classes +Spring Boot Devtools only detects changes to .class files. You need to enable the *automatic build* feature in your IDE which detects source file changes and rebuilds the .class file. If not, you have to manually rebuild your project to restart your CAP Java application. ::: -### Multitenant Applications +## Multitenant Applications With the streamlined MTX, you can run your multitenant application locally along with the MTX sidecar and use SQLite as the database. See [the _Multitenancy_ guide](../../guides/multitenancy/#test-locally) for more information. - ## Debugging -You can debug both local and remote Java applications. +You can debug Java applications locally and remotely. -- For local applications, it's best to start the application using the integrated debugger of your [preferred IDE](../../tools/cds-editors). +- For local applications, it's best to start the application using the integrated debugger of your [preferred IDE](../../tools/cds-editors). +- You can also enable debugger using JVM arguments and attach to it from your IDE. - Especially for remote applications, we recommend [`cds debug`](../../tools/cds-cli#java-applications) to turn on debugging. + +## Spring Boot Devtools + +Use [Spring Boot Devtools](https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools) in your CAP Java application to speed up local development. + +Once this is added, you can use the restart capabilities of the Spring Boot Devtools while developing your application in your favorite Java IDE. Any change triggers an automatic application context reload without the need to manually restart the complete application. Besides being a lot faster than a complete restart this also eliminates manual steps. The application context reload is triggered by any file change on the application's classpath: + +* Java classes (for example, custom handlers) +* Anything inside src/main/resources + * Configuration files (for example, _application.yaml_) + * Artifacts generated from CDS (schema.sql, CSN, EDMX) + * Any other static resource + From 82ab7a5e914866445d9e388b7c6d5ed043db5969 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 18 Aug 2025 12:10:43 +0200 Subject: [PATCH 3/7] Update java/developing-applications/running.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: René Jeglinsky --- java/developing-applications/running.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/developing-applications/running.md b/java/developing-applications/running.md index c477031963..cba2db7990 100644 --- a/java/developing-applications/running.md +++ b/java/developing-applications/running.md @@ -99,7 +99,7 @@ You can customize the goals that are executed when the application is restarted ``` ::: warning Restart for changed Java classes -Spring Boot Devtools only detects changes to .class files. You need to enable the *automatic build* feature in your IDE which detects source file changes and rebuilds the .class file. If not, you have to manually rebuild your project to restart your CAP Java application. +Spring Boot Devtools only detects changes to .class files. You need to enable the *automatic build* feature in your IDE which detects source file changes and rebuilds the _.class_ file. If not, you have to manually rebuild your project to restart your CAP Java application. ::: ## Multitenant Applications From f42920071c75c8628165f6b2cf2e6b6929fd9d60 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 18 Aug 2025 12:10:53 +0200 Subject: [PATCH 4/7] Update java/developing-applications/running.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: René Jeglinsky --- java/developing-applications/running.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/developing-applications/running.md b/java/developing-applications/running.md index cba2db7990..f1617d6217 100644 --- a/java/developing-applications/running.md +++ b/java/developing-applications/running.md @@ -36,7 +36,7 @@ To use the `cds` prefix of the `cds-maven-plugin` from everywhere, add the plugi ``` -This uses the [Maven plugin prefix resolution](https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html) feature. This Maven feature allows you to use only the `cds` prefix of the `cds-maven-plugin` to execute goals of this plugin. For example, instead of `mvn com.sap.cds:cds-maven-plugin:watch` you can use the shorter variant `mvn cds:watch` to run the `watch` goal of the `cds-maven-plugin`. +This uses the [Maven plugin prefix resolution](https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html) feature. This Maven feature allows you to use the `cds` prefix of the `cds-maven-plugin` to execute goals of this plugin, like `watch`, from everywhere. ## Run Java application in your IDE From d292b29dd9d2a4bbe33a03a95f21a72979d20d43 Mon Sep 17 00:00:00 2001 From: Vladimir Mikhaylenko Date: Mon, 18 Aug 2025 12:24:03 +0200 Subject: [PATCH 5/7] Fix anchor links --- java/developing-applications/running.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/developing-applications/running.md b/java/developing-applications/running.md index f1617d6217..dcdf2d7647 100644 --- a/java/developing-applications/running.md +++ b/java/developing-applications/running.md @@ -6,7 +6,7 @@ status: released uacp: Used as link target from Help Portal at https://help.sap.com/products/BTP/65de2977205c403bbc107264b8eccf4b/9186ed9ab00842e1a31309ff1be38792.html --- -# Running Applications +# Running Applications { #local-development-support }