Spring boot + angular 2 Heroku deployment - java

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

Related

Spring boot basic guide: How to create complete folder?

I'm creating basic spring boot application as in this guide
If I download their completed-guide-code, I get the complete folder to run and test app.
But if I do practice as start from scratch, install prequisite, go to start.spring.io and config, generate starting project, create web app, create app class, and go to step Run the Application, I cannot find the folder complete as in guide, so I can't run and test app. Maybe I should run some build command to create it? So how to create it?
Please just run mvn spring-boot:run (use mvnw if maven is not installed or not on path. Spring boot project contains mvnw executable) in the project root without the directory specifier.
./ could be used for unix like systems but not windows.
complete folder is just the root project name in the guide. In your case, the root project name is spring-boot, go to spring-boot directory and run ./mvnw spring-boot:run.

Deploy maven multi module project in GC

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!

Java Spring-boot: Problem to finde resources

I have a Spring-boot backend Angular front end application. The application runs well if it is run on port 4200 (Running frontend from the front end). But I have done the integration an I run in to troubles. The application after the following commands:
mvn clean install
npm install
npm build
Properly generate the dist folder on the front end and copy them in the source folder (project/src/main/resources/static).
When I try to run the application from the back end (definded port 8999) the application finde the index.html file in static folder but cannot find the other scripts. The application start looking for those resources on localhost:8999/resourcefile
instead of looking for it in
localhost:8999/src/main/resources/static
Do anyone have any idea?
For anyone with the same problem. There was declared
<base href="/">
in my index.html and that's why it was looking for resources from the wrong directory.

Deploying Java Application to Heroku

So I made a java web application with a normal pom.xml specifying my maven dependencies. Then, I went through the Heroku step by step tutorial on deploying their already-made web app, which did not help in the least bit. Then, I tried deploying the war, with no luck. Then I tried using the Maven plugin. I'm not sure if Heroku or some blog has a step by step guide on deploying to Heroku, but I need one. Can anyone go over what modifications need to be done to the pom.xml and what the procfile should be? And is it also necessary to have a main method in a java class? I thought each servlet was an entry point. My web app works fine on localhost and when I deploy the war on tomcat. It just doesn't work on Heroku no matter what I do to the pom.xml. I included my pom.xml. enter link description here
Run these commands:
$ heroku plugins:install heroku-cli-deploy
$ heroku deploy:war yourapp.war
Then read WAR Deployment on Heroku's Dev Center.

git push heroku master does not push java maven target/dependency directory to heroku

When I do a git push heroku master on my java application, it does not push the "target/dependency" directory to heroku.
I followed the example for my application and the Procfile shows web: java -cp target/classes:target/dependency/* HelloWorld which seems to imply that the target/dependency directory can be there.
My build creates everything correctly and foreman executes the application correctly but when I push to heroku, the dependency directory is missing and the application fails to execute because those dependencies are missing.
What am I doing wrong here?
You need to make sure your target/dependency directory is committed to your git repository before you push.
Use the git status command to see if it is committed.

Categories