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.
・ 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.
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. Then go to the Setting tab and Specify the build pack. This time it's Java. Added.
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. Select "maven-archetype-webapp" as the architecture type. Various parameters look like this. After creating it, we will make some modifications.
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.
When you create a Maven project, the default is Java5, so select Java8.
Maybe this step isn't necessary, but I'm using Tomcat 8 in my environment so I added that runtime.
This is also Java 5, so change it to Java 8.
package: After creating dev.local, copy the file as shown in the picture.
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>
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
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. If you try to execute it and "BUILD SUCCESS" is displayed, it is finished once.
When the build is finished, the war file is created, so I will try to put it on the local Tomcat. When I called it from the browser, it was displayed safely.
From here, follow the steps on the deploy tab of the Heroku admin console. When you're done with git push heroku master, try hitting the heroku ps command Check the status of Webapp. Access it with a browser, and if the following is displayed, it is complete.
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