I have spring source tool with Maven. And I have one Java project which I want to deploy on Heroku.
Can anybody tell me steps to deploy on Heroku?
Many Thanks
Create war file in Maven. You can do this by referring here
Install the Heroku Toolbelt from here
Open the command prompt (for Windows) and type:
heroku login
It will prompt to enter user name and password. Enter the credentials of your heroku account.
Now, to install the heroku-deploy plugin, enter the code:
heroku plugins:install heroku-cli-deploy
Now deploy the war file to the heroku server by this code:
heroku deploy:war --war <path_to_war_file> --app <app_name>
If you are in an application directory, the --app parameter can be omitted:
heroku deploy:war --war <path_to_war_file>
Your App will be successfully deployed to the heroku server.
It's all well explained here :
https://devcenter.heroku.com/articles/java
How to deploy war file to Heroku
Register Heroku account
Install heroku-cli
Install JDK if needed
Install heroku-cli-deploy plugin using command:
heroku plugins:install heroku-cli-deploy
Login to heroku in command line:
heroku login
Create app using command:
heroku apps:create <app_name>
Deploy war file using this command:
heroku war:deploy <path_to_war_file> --app <app_name>
Open app using command:
heroku open -a <app_name>
Reference: Heroku Deploy War/Jar
This url shows exactly how to deploy a war file on heroku:
https://github.com/heroku/heroku-deploy
Related
I'm trying to edit the Procfile in Heroku, however it seems like you can't edit it when using the command heroku war:deploy myapp.war to deploy the war file. Any suggestion on how i can either edit this, or run another shell script in web phase?
I've tried to include the Procfile directly with --include, however it gets overwritten by the default Procfile which is provded by Heroku.
heroku war:deploy doesn't support a custom Procfile. However, you can customize the command using the following config vars:
JAVA_OPTS
WEBAPP_RUNNER_OPTS
You can set this with a command like heroku config:set WEBAPP_RUNNER_OPTS="..."
I'm trying to upload my 1st Java Web app to the web but I can't handle the Procfile. After deploy, there is info about successfully deploy but when I try to run the app there are an error and server logs seems to indicate that Procfile is empty / does not exist.
In server resources there is following dyno:
java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war
and in thetutorial there is
"Your Procfile will look something like this:"
web: java $JAVA_OPTS -cp target/classes:target/dependency/* HelloWorld
but I don't udnerstand what is happening here. I know only that there should be web: at the beggining for web-app I don't understand the rest of it. Can some one help me undrstand it so I could create proper Procfile for my app?
If you have heroku installed and if you have only .jsp and .class you can do as it follows, and you don't need a procfile:
$ heroku create <app_name>
Create a WAR file of your app in Eclipse for example:
Right click on the project > Export > WAR file
then you have to deploy it to heroku:
$ heroku war:deploy <path_to_war_file> --app <app_name>
then you'll see the app going to heroku, some logs and blah blah blah. After that you can open your application:
$ heroku open --app <app_name>
Simple. But if you need some help about procfile, take a look here
I have an existing Java web app project. It works locally with Tomcat. I converted it into a maven project and deployed it on Heroku using webapp-runner. The application is deployed successfully but it does not run; it crashes. I cannot figure out from the logs what the reason is.
My Procfile looks like this: web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war
App structure
logs
It states clearly in the log: The specified path target/*.war does not exist. Run your build locally using mvn clean package and see if you actually have a war file in the target directory and what it's name is.
Then, open your Procfile and replace target/*.war with target/whateverTheNameIs.war and retry.
I'm working on a Java web application. I already deploy it to heroku. Now I'm trying to remote debug my application using IntelliJ with no results. To deploy it I use git, then heroku starts it reading and executing the Procfile. And here is the problem. Everywhere I see that to debug I must use this line in my Procfile: web: java -agentlib:jdwp=transport=dt_socket,server=y,address=9090,suspend=n -jar target/myapp.jar. But I can't put this line on my Procfile because I execute my app using web: sh target/bin/webapp and not java. There's some workaround to simply debug my application.
You'll need Heroku Exec and the Heroku Java CLI.
First, put your agentlib args into the JAVA_TOOL_OPTIONS env var:
$ heroku config:set JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,address=9090,suspend=n"
This way, the java process in your target/bin/webapp script will pick it up automatically.
Then run:
$ heroku ps:forward 9090
And you can connect to localhost:9090 from your IDE.
I have a working app using Spring Framework + AngularJs front-end.
I do deploy it on amazon AWS before by simply packaging mvn package into .war file.
Now I need to setup a linux env in docker locally to debug some additional functionality (Using windows as the main OS) and preferably to deploy this docker container in future.
I do seen some articles on dockerizing the Spring Boot app.
This is the example dockerfile from spring.io
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD gs-spring-boot-docker-0.1.0.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
My question is - how do I run my .war file on docker container?
If you're looking to run this application on your local Linux machine, then you can create this Dockerfile in the same directory where the WAR file exists.
FROM tomcat:8.0.21-jre8
RUN [“rm”, “-rf”, “/usr/local/tomcat/webapps/ROOT”]
COPY dbconnect.war /usr/local/tomcat/webapps/ROOT.war
CMD [“catalina.sh”, “run”]
You can then build the Docker image and provide your custom tag:
docker build -t <your-username>/tomcat-example:latest .
Finally you can run this container.
docker run -p 8080:8080 -d --name tomcat <your-username>/tomcat-example:latest
You can check out these detailed examples here if need to run this application with a database or a web server.
https://github.com/dchqinc/dchq-docker-java-example
https://dzone.com/refcardz/java-containerization
You don't deploy a .war file in docker just like you deploy it into a tomcat server. You need to have a main(String args[]) entry point which is also specified in your jar's manifest file. Your app.jar specified as ENTRYPOINT will then run your main(). Inside the main() you can run an embedded web server which runs your application.
If you configure/package your Spring Boot app as an executable .jar instead of a .war (Spring Boot Initializr will do this for you if you select the .jar option), then running it in your container is a matter of adding an entrypoint to run java with -jar and your jar name, like
ENTRYPOINT ["java", "-jar", "/opt/yourapp-0.0.1-SNAPSHOT.jar"]