Thursday, December 19, 2013

Adding an Eclipse Project to Heroku

I'm still picking up the pieces, just want to record what I did, not that I fully understand every step.

Heroku has tutorials on creating Java app from command line and using Eclipse. The Eclipse tutorial shows you how to use the plug-in to create the Heroku project. I want to see how I can create an independent Maven project in Eclipse, then push it up to Heroku.

This writing assumes your Heroku account and git is all setup properly.

1. I created a Maven project inside Eclipse. I used the Spring MVC archetype from here: http://maven-repository.com/artifact/co.ntier/spring-mvc-archetype/1.0.2

I noticed that Git is not happy when I created the project in default workspace. Not sure why, so I picked a separate spot. Since Heroku plugin uses "C:\Users\ymeng\git", so I just picked that spot.

2. I added the Procfile, here is the content
web: java $JAVA_OPTS -Dspring.profiles.active=prod -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

3. I added the following to the pom.xml
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals><goal>copy</goal></goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.github.jsimone</groupId>
                                <artifactId>webapp-runner</artifactId>
                                <version>7.0.40.0</version>
                                <destFileName>webapp-runner.jar</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
4. In Eclipse, right click the project, select "Team", then follow the options to pick "git" 

5. I set the .gitignore in my project root directory to:
/target
.settings
6. Then go to "Team" again, and select "commit", pick the files (i picked all). Now your project is committed.
7. This step, i have to do it from the command line:
go to your project root directory, assuming you logged to Heroku already, run "heroku create yourappname". This step will create the git remote for you and also setup "yourappname" on Heroku site for you.
8. Go to "Team" again, select "remote > push", it will asks you to put in your "master" branch.

If all works fine, then your app is on Heroku now.