Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Working with Bundler
      • Rails Support
    • Python
      • Background Jobs in Python
      • Working with Django
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with the Play Framework
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Data For Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Single Sign-on (SSO)
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Deployment
  • Deployment Integrations
  • Deploying Java Applications to Heroku from Eclipse or IntelliJ IDEA

Deploying Java Applications to Heroku from Eclipse or IntelliJ IDEA

English — 日本語に切り替える

Last updated April 10, 2020

Table of Contents

  • Setting up the Heroku Maven Plugin
  • Deploying from Eclipse
  • Deploying from IntelliJ IDEA
  • Troubleshooting

Many Java developers find that deploying from an IDE is a more natural fit than deploying from the command-line. In this article, you’ll learn how to deploy to Heroku from two popular Java-based IDEs: Eclipse and IntelliJ IDEA. In both cases, you’ll use the Heroku Maven Plugin to do the heavy lifting.

Setting up the Heroku Maven Plugin

If you have an existing project using the Heroku Maven Plugin, then you can use it for the steps in this article. If you do not, then start by cloning the sample project:

$ git clone https://github.com/kissaten/maven-plugin-war-example

Then create a new Heroku application by running the following command:

$ heroku create
Creating gentle-shore-6874... done, stack is heroku-18
https://gentle-shore-6874.herokuapp.com/ | git@heroku.com:gentle-shore-6874.git

Next, you’ll need to have one one of the IDEs installed. You can download and install Eclipse as describe on the Eclipse download site. For IntelliJ, you can download and install either the free Community edition or begin a free-trial of the Ultimate Edition. Once your IDE is installed, you can use it to open your project.

To open your project in Eclipse, select File > Import... from the Eclipse menu. Then choose Maven and below that, Existing Maven Projects. Click Next, and enter the location of the Git project you cloned for “Root directory”. Then click Finish. After a few seconds, your project will appear in the “Package Explorer”

To open your project in IntelliJ IDEA, choose File > Open and then select the directory location of the Git project you cloned.

Deploying from Eclipse

You can watch a short video demonstration of Eclipse deployment.

In the “Package Explorer” pane (usually on the left side of the window), expand the project so you can see its files. Then right-click on the pom.xml and select Run As > Maven build....

Run the a Maven build from Eclipse

In the dialog that appears, enter heroku:deploy-war in the “Goals” field, as shown here.

Enter Heroku Maven Goal

If you were deploying a standalone Java application, you could use the heroku:deploy target to deploy without a WAR file. For more information on deploying standalone apps, see the Heroku Maven Plugin documentation.

On some platforms, including Windows, you will also need to set the HEROKU_API_KEY environment variable for the task. Click the Environment tab, and select New... to create a new variable. Enter “HEROKU_API_KEY” for the name and your API key for the value. You can get your API key by running heroku auth:token at the command-line.

Eclipse Environment Variable

Now click Run, and the deployment will start. In the “Console” pane you will see something like this:

Eclipse Maven Console

Open your application by running $ heroku open -a <app-name> from the command-line, or by browsing to https://<app-name>.herokuapp.com (but replace <app-name with the name of your app).

Generating launch configurations

You can optionally run a Maven command (either from the terminal or from Eclipse) to generate launch configurations for common goals:

$ mvn heroku:eclipse-launch-config

The will create a number of *.launch files in the root of your project. You can click these files in Eclipse to run them.

Deploying from IntelliJ IDEA

Before opening IntelliJ, ensure that your M2_HOME environment variable is set to the location of your Maven installation. If you would prefer not to set this variable, then you may need to configure the path to your Maven installation under Preferences -> Maven within IntelliJ.

To deploy, select Run -> Edit Configurations from the IntelliJ IDEA menu. Then select the + button to create a new Maven configuration.

Create new Maven Configuration in IDEA

Then name the configuration “Heroku Deploy”, and enter heroku:deploy-war in the “Command Line” field as shown here.

Configure IDEA Maven Goal

If you were deploying a standalone Java application, you could use the heroku:deploy target to deploy without a WAR file. For more information on deploying standalone apps, see the Heroku Maven Plugin documentation.

Click OK. Now a “Heroku Deploy” task will be shown in the Run Configurations toolbar. Press the green arrow button next to it.

Run the Maven Goal from IDEA

In the “Console” pane you will see something like this:

IDEA Maven Console

Open your application by running $ heroku open -a <app-name> from the command-line, or by browsing to https://<app-name>.herokuapp.com (replace <app-name with the name of your app).

Troubleshooting

If you receive the error Failed to deploy application: Forbidden, such as:

[ERROR] Failed to execute goal com.heroku.sdk:heroku-maven-plugin:0.4.1:deploy-war (default-cli) on project helloworld: Failed to deploy application: Forbidden -> [Help 1]

This indicates that the Maven plugin cannot find your app. Check that you have a “heroku” remote in your Git repository by running this command:

$ git remote
heroku
origin

Then try adding your application name to the pom.xml in the plugin configuration like this:

<configuration>
  <appName>gentle-shore-6874</appName>
</configuration>

Your app name will be something other than “gentle-shore-6874”.

If you receive the error Failed to deploy application: Unauthorized, such as:

[ERROR] Failed to execute goal com.heroku.sdk:heroku-maven-plugin:0.4.1:deploy-war (default-cli) on project helloworld: Failed to deploy application: Unauthorized -> [Help 1]

This means that you are not authorized to deploy to the configured application. Check that you are logged into the toolbelt by running this command:

$ heroku auth:whoami
ide-test@heroku.com

Then check that the value in your HEROKU_API_KEY is correct.

For more information on using Maven with Eclipse, see the Eclipse documentation. For more information on using Maven with IntelliJ IDEA, see the IntelliJ documentation.

For more information on the Heroku Maven plugin, see the DevCenter article Deploying Java Applications with the Heroku Maven Plugin.

Keep reading

  • Deployment Integrations

Feedback

Log in to submit feedback.

WAR Deployment GitHub Integration (Heroku GitHub Deploys)

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies
  • Cookie Preferences