Vaadin 14 Spring Boot App run from command line in ProductionMode - spring-boot

I want to run the spring boot application from a jar with embedded tomat, like I run other spring-boot apps.
The project is running fine, when started from IDE.
I want to run it from jar, but i get this error in the browser:
Failed to find the bundle manifest file 'frontend://vaadin-flow-bundle-manifest.json' in the servlet context for 'ES6' browsers.
I have set the productionMode to true in both application.properties and pom.xml. Why it is such a hustle? I don't know how to produce this json file. How to just run this project even in dev mode?
I start the project with:
mvn clean && mvn package -Pproduction && mvn spring-boot:run -Pproduction

Related

Spring boot build without starting up the application

I want to build the spring boot jar file using maven like
mvn -B clean install -Pdev -DskipTests
But I do not want to start the spring boot app while doing this process as it cannot connect to the database from this build machine. How can I do that? Now the build is failing as it is trying to start up the server during the build process

How to debug spring boot maven project in debug mode in Intellij?

I run my maven project with the following command for dev profile from my terminal
sudo mvn spring-boot:run -Dspring.profiles.active=dev
How can I run my project to run in debug mode with given profile. How to set configuration in intellij for this?
Running a Spring Boot project from Maven with a specific profile
mvn spring-boot:run -Dspring-boot.run.profiles=foo,bar
Or by using a shell variable
SPRING_PROFILES_ACTIVE=foo mvn spring-boot:run
Or by passing arguments to the JVM
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=foo,bar"
These are the only methods that I know of that work for Spring Boot v2.0+.
The first option is recognized by the Spring Boot Maven plugin and passes it on to the application JVM.
Since version 2.0 of Spring Boot, the run goal forks the process by default. Since -Dspring.profiles.active is not recognized by the plugin directly, it's only seen by the Maven process and not passed on to the app itself. This is why it doesn't work in the form mvn spring-boot:run -Dspring.profiles.active=foo,bar.
In the second option, the shell variable should be visible to any subprocesses spawned from that shell.
Starting a Spring Boot project in debug mode from Maven
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Putting it together
mvn spring-boot:run -Dspring-boot.run.profiles=foo,bar -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Alternative, passing all arguments to JVM
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 -Dspring.profiles.active=foo,bar"
The Maven pom.xml should include the Spring Boot plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.1.RELEASE</version>
</plugin>
In IntelliJ you should create a new "Remote" debug configuration from the "Run/Debug Configurations" tool window. You'll find it in the main menu - "Run / Edit Configurations..."
The default config will use the same 5005 port.
After that, launch that debug config. The console should display "Connected to the target VM...".
Sources:
https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/maven-plugin/examples/run-profiles.html
https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/maven-plugin/examples/run-debug.html
If you're running from maven, then add the following parameters:
mvn spring-boot:run -Dspring.profiles.active=dev -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5555"
Here 5555 is a debug port number (you can use any other unoccupied port).
Then in IntelliJ you can use Remote Debug configuration and connect to that port.
If you open the pom.xml from intelliJ, you can create a Run Configuration with --spring.profiles.active=dev and main class that is a class with method main just like in a regular the most simple java application.
Just click run button (green triable button) then click Debug...
IntelliJ will run your spring-boot app in debugging mode
If you want to run with arguments just open edit configuration and put your args in VM Options/Program arguments like

Is there any meaning to running -Dspring.profiles.active=dev,runtime when running Spring Boot locally?

In my team I frequently (>10) see Spring Boot projects with the following instructions for running locally:
mvn clean spring-boot:run -Dspring.profiles.active=dev,runtime
My understanding of Spring Boot profiles is that each one corresponds to a particular environment, eg dev, test - so you would never need more than one. Also that each profile name corresponds to a particular env file - eg src/main/java/resources/application-dev.yml application-test.yml etc.
I would have thought that you would run the app on your local machine with:
mvn clean spring-boot:run -Dspring.profiles.active=local
And have the local configuration in:
src/main/java/resources/application-local.yml
This is running:
Java 11
maven parent is org.springframework.boot spring-boot-starter-parent 2.2.6.RELEASE
maven version is 3.3.9
My question is: Is there any meaning to running -Dspring.profiles.active=dev,runtime when running Spring Boot locally?

The Maven Command With spring-boot:spring-image Doesn't Work As What It Should Do

For a spring boot 2.3 project, I run
./mvnw spring-boot:build-image
and it yields the same outcome as
./mvnw spring-boot:run
which run the application, but doesn't create a Docker image.
For its sister project with the same set of dependencies, the command works properly.
How to solve the problem?

Running API tests in Teamcity build step

I have a Spring Boot Maven app. There is a bunch of API tests using RestAssured, inside the project. These tests are not marked as #SpringBootTest, therefore when running them, the context of the application is not raising so to make tests pass the application must be up and running before.
I'm creating a Teamcity build in which I want to:
Start the app
Run RestAssured tests
Create an artifact
I'm using an Agent with maven installed.
The question is:
How can I create a build step where I run the application on a defined port and then run api tests
against it?
What I've tried is creating such build steps:
Command line: mvn spring-boot:run & sleep 50s mvn test
Maven step/command line: mvn clean package -DskipTests
I thought the spring boot application will start and tests will be ready to start after some time. On successful step 1 I create an artifact.
The problem is that the build step is never exited because of spring boot app running (blocking terminal).

Resources