I have a springboot application that is deployed to an external tomcat server, everything works in my local with local DB. Now, i have to promote the code to higher environments where the DB configurations are different. I read a lot about profiles with -Dspring.profiles.active=dev etc.., but how will the spring project know which server it is in when its an external tomcat and not using
java -jar -Dspring.profiles.active=dev demo-0.0.1-SNAPSHOT.jar
You can pass the SPRING_PROFILES_ACTIVE=dev environmental variable using CATALINA_OPTS
Here is all the ways to externalized properties and setting profiles docs
You should link spring boot profile with maven one like this .
Thus you can build your jar package specifying the spring boot wanted profile :
mvn clean install -P Prod
Related
I'm new to google cloud and I need to deploy my java application there.
Currently it consists of 1 one web-module and directory structure looks like this:
clinic_project
acms-frontend
pom.xml
pom.xml
And start script:
#!/bin/bash
nohup mvn clean install
serv=acms-frontend
cd $serv
nohup mvn spring-boot:run -Dspring.profiles.active="dev" -DAUTH0_CLIENT_ID=".." -DAUTH0_CLIENT_SECRET=".." -DACMS_CRYPTO_KEY=".." -DACMS_NODE_NAME="n/a" -DACMS_POD_IP="n/a" -DACMS_POD_NAMESPACE="n/a" -DACMS_POD_NAME="n/a"
Inside web-module I have .yml file with default port and other variables.
I've installed gcloud SDK and understand how I can deploy single module application.
But how can I tell google cloud to deploy my multi-module project with commands sequence from script?
If you want to deploy multiple modules, you can do so with the following command: gcloud app deploy ~/my_app/app.yaml ~/my_app/another_service.yaml as mentioned in the gcloud app deploy documentation examples.
Make sure to add the module/service name in the app.yaml files as mentioned in this other document, otherwise you may run into some naming issues with them.
Hope you find this useful!
I have a big issue. I'm trying to deploy Spring Boot + Angular 2 web app on heroku but don't know how to do it. I tried several things including:
Making a .war file and deploying it to heroku (source here)
Deploying project as standard java application (source here)
but none of these worked. The first attempt didn't work because I constatly got 404 not found, and the second one didn't work due to, I think, some jar file wasn't found in the location which was described in the Procfile.
Can anyone give me a link, an example, or write a step by step instruction how to achieve this. Thank you.
The most simple way to do it:
run ng build in angular 2 project root (if you are using angular-cli) and copy the content of dist folder to src/main/resources/static/.
create Procfile (for maven):
web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/*.jar
commit and push changes.
Also, you need spring-boot-starter-web present in dependencies. Which has embedded tomcat and automatically configured to serve static content from the static folder.
If you deploy your app as a standard Java application, you can combine it with the Node.js buildpack to run ng build during the Heroku build.
$ heroku buildpacks:add heroku/nodejs
$ heroku buildpacks:add heroku/java
$ git push heroku master
The Node.js buildpack will detect your package.json, install Node.js and run npm. Then the Java build can proceed as normal.
There is a guide for doing something very similar but with Grunt: Using Grunt with Java and Maven to Automate JavaScript Tasks
Use JHipster: https://jhipster.github.io
Once installed, run:
$ yo jhipster
Then run
$ yo jhipster:heroku
I am new to spring boot and I would want to know the basics of it. I am creating a project with jHipster. When I install gulp on my system I can see the project running at port 9000. I however want to deploy the same application on my local using tomcat apache server.
Can I debug my code in java using the same server installed during the time of spring boot or do I need a separate server like apache?
From JHipster documentation "Profiles" :
If you're using Maven Wrapper (mvnw)
./mvnw package
If you're using Gradle Wrapper (mvnw)
./gradlew bootRepackage
Should produce WAR with development profile as
By default, JHipster will use the dev profile
I think you can deploy this WAR on your usual Tomcat
I've a Spring boot(with embedded tomcat 8) project with multiple server components that get deployed in multiple env(dev/test/prod) How do you make one jar that can be deployed into multiple env in such a way that in each env the jar will pick up appropriate env params such as db and other server urls that each env supposed to use. The objective is not to touch the jar file which invalidates QA process. If it's traditional deployment, I typically change a flag in the properties file to indicate the env and the rest of the properties are read based on that param.
You package your jar (or war) as mvn package and then to execute add a -D.spring.profiles.active parameter setting your environment: something like: mvn spring-boot:run -Dspring.profiles.active=dev
Check this and this documentation.
Heroku allows the option of directly deploying one's Java .war file using heroku deploy:war (the Procfile is automatically managed by heroku in this case).
How does one use NewRelic with such a setup? The current documentation on Heroku DevCenter on NewRelic asks one to place the NewRelic jar in the root folder of the Java application.
How does one achieve this when using heroku deploy:war to directly deploy the app and not via git?
Following up on this question from New Relic support and adding clarifying statements to this old question. Unfortunately as far as I'm aware, it isn't possible to use the New Relic .jar file in an embedded war file without exploding the war.
On Heroku, using deploy:war simply wraps your war in jetty runner. An alternative would be to deploy an app that uses jetty runner by deploying source code instead of a binary. Instructions are here:
If you use the approach above, you should be able to add New Relic to your project.
I received this response from Heroku Support team:
WAR deploy doesn't specifically handle this case. However, it should
work. You can include the New Relic JAR in your WAR and add the
javaagent flag in your JAVA_OPTS config.