Deploy a Tomcat-based Eclipse project on Heroku

Preface

It seems that there are various ways to publish Java applications on Heroku, but when developing locally using Tomcat in orthodox, the production environment is Heroku, and it is a correspondence memo when it becomes.

Advance preparation

・ Pleiades All in One Eclipse Release 2018-09 (Compatible with Eclipse SimRel 2018-09) ・ Heroku -Check until "Hello World on Heroku !!" (still local) is displayed in the Dynamic Web Project in Eclipse. devtest_heroku01.png

Preparations on Heroku side

This step comes first because I wanted to secure the application name first, but it is also possible after conversion to the Maven project that I am doing later. This time, I created it with the name devtest-heroku as follows. devtest_heroku02.png Then go to the Setting tab and devtest_heroku03.png Specify the build pack. devtest_heroku04.png This time it's Java. devtest_heroku05.png Added. devtest_heroku06.png

Convert to Mave project

However, it is not a conversion, but here we will take the method of new creation ⇒ copy. First, create a new Maven project. I named it devtest-heroku. devtest_heroku07.png Select "maven-archetype-webapp" as the architecture type. devtest_heroku08.png Various parameters look like this. devtest_heroku09.png After creating it, we will make some modifications.

Build path correction

devtest_heroku10.png It is said that the project folder / src / main / java and the project folder / src / test / java do not exist, so create them physically. For Windows, you can use Explorer.

JRE changes

devtest_heroku11.png When you create a Maven project, the default is Java5, so select Java8.

Add server runtime

devtest_heroku12.png devtest_heroku13.png devtest_heroku14.png Maybe this step isn't necessary, but I'm using Tomcat 8 in my environment so I added that runtime.

Project facet changes

This is also Java 5, so change it to Java 8. devtest_heroku15.png devtest_heroku16.png

Copy of source code

package: After creating dev.local, copy the file as shown in the picture. devtest_heroku17.png

Modify pom.xml

I think that the file with the following contents has been created at the stage of creating the Maven project,

pom.xml


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>dev.local</groupId>
  <artifactId>devtest-heroku</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>devtest-heroku Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>devtest-heroku</finalName>
  </build>
</project>

As below -Added the dependency of Servlet to dependencies -Added plugins under build (added Tomcat webapp-runner.jar) Did.

pom.xml (after modification)


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>dev.local</groupId>
  <artifactId>devtest-heroku</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>devtest-heroku Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
  </dependencies>
  <build>
    <finalName>devtest-heroku</finalName>
    <plugins>
	    <plugin>
		    <groupId>org.apache.maven.plugins</groupId>
		    <artifactId>maven-dependency-plugin</artifactId>
	        <executions>
	        	<execution>
	            	<phase>package</phase>
	            	<goals><goal>copy</goal></goals>
	            	<configuration>
	                    <artifactItems>
	                        <artifactItem>
	                            <groupId>com.github.jsimone</groupId>
	                            <artifactId>webapp-runner</artifactId>
	                            <version>9.0.11.0</version>
	                            <destFileName>webapp-runner.jar</destFileName>
	                        </artifactItem>
	                    </artifactItems>
	                </configuration>
	            </execution>
	        </executions>
        </plugin>
    </plugins>
  </build>
</project>

Creating a Procfile

It seems that it is the content that is executed when Webapp is started on Heroku side, and the content is a Java command. This is OK if created before deploying Heroku. Create directly under the project.

Procfile


web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

Maven project build

It becomes the build setting. Right-click pom.xml ⇒ Run ⇒ Select Maven Build, the following screen will appear. Set as shown in the red line and red frame. devtest_heroku18.png If you try to execute it and "BUILD SUCCESS" is displayed, it is finished once. devtest_heroku19.png

Try putting it on tomcat

When the build is finished, the war file is created, so I will try to put it on the local Tomcat. devtest_heroku20.png When I called it from the browser, it was displayed safely. devtest_heroku21.png

Deploy to Heroku

From here, follow the steps on the deploy tab of the Heroku admin console. devtest_heroku22.png When you're done with git push heroku master, try hitting the heroku ps command Check the status of Webapp. devtest_heroku23.png Access it with a browser, and if the following is displayed, it is complete. devtest_heroku24.png

At the end

Thank you for referring to the poor procedure to the end. It can be converted directly without creating a new Maven project, so it may be more efficient to do it there. If the various versions change, the movement will change again, so I think that it is just the procedure at the moment. It would be nice to have an Eclipse Heroku plug-in.

Recommended Posts

Deploy a Tomcat-based Eclipse project on Heroku
Deploy a war file on Heroku
Deploy a Java web app on Heroku
[Java] Deploy a web application created with Eclipse + Maven + Ontology on Heroku
Deploy Vapor Project to Heroku
How to deploy on heroku
How to deploy a simple Java Servlet app on Heroku
Create a tomcat project using Eclipse
Create a Java project using Eclipse
Deploy Flask's Docker image on Heroku
Deploy Rails on Docker to heroku
Deploy your Rails app on Heroku
heroku deploy
A memorandum on how to use Eclipse
Import nablarch-example project on github into Eclipse
How to redo a deployment on Heroku
How to deploy a container on AWS Lambda
Deploy a Spring Boot application on Elastic Beanstalk
How to deploy to Heroku from a local docker image
[CentOS, Eclipse] Load a library file in a C project
Deploy the Spring Boot project to Tomcat on XAMPP
Eclipse ~ Java project creation ~
Steps to deploy to Heroku
Introducing Bugsnag on Heroku
Deploy RAILS on EC2
Yay! I'm on Heroku!
Use Corretto 11 on Heroku
Error resolution on Heroku
A collection of commands that were frequently used on heroku
Create a base for your batch processing project in Eclipse.
Programmatically import a Maven project from your own Eclipse plugin
Create a tomcat project using Eclipse Pleiades All in One
How to deploy a kotlin (java) app on AWS fargate
How to deploy a Rails application on AWS (article summary)