Your app is ready!

This is a template for a lightweight RESTful API using JAX-RS. The sample code is a call for getting the current time. To try it out use the example REST client below to send a GET request to /services/time. Then use Eclipse or the Command Line to deploy some changes.

Using Eclipse 3.7:

Step 1. Setup your environment

  1. Ensure EGit is installed.
  2. Ensure the Maven Eclipse Plugin is installed.
  3. Create an SSH key if you haven't already:
    1. Go to Window Preferences General Network Connections SSH2
    2. Choose the Key Management tab
    3. Click Generate RSA Key... SSH Eclipse Preferences Window
    4. Copy the generated public key in the text box and add it to your account
    5. Click Save Private Key..., accepting the defaults
    6. Click Ok

Step 2. Clone the App

  1. Go to File Import... Git Projects from Git Import
  2. Choose URI and click Next
  3. Enter git@heroku.com:.git in the URI field. Clone Git Repository
  4. Click Next three times
    Click Yes to the question of authenticity if the question appears.
  5. Choose Import as general project Import Projects from Git
  6. Click Finish

Step 3. Configure the App

  1. Right-click the project root
  2. Choose Configure Convert to Maven Project

Step 4. Makes some changes to the app

  1. Open src/main/java/com/example/services/TimeService.java
  2. To add a new resource path that supports specific time zones (e.g. GET /services/time/est for the time in Eastern Standard Time), add this method:
    @GET
    @Path("/{timezone}")
    public Time get(@PathParam("timezone") String timezone) {
        return new Time(TimeZone.getTimeZone(timezone.toUpperCase()));
    }
    Be sure to also add the necessary import statements:
    import javax.ws.rs.PathParam;
    import java.util.TimeZone;
    

Step 5. Deploy to Heroku

  1. Right-click the project root and choose Team Commit
  2. Enter a commit message and click Commit Commit Changes
  3. Right-click the project root and choose Team Push to Upstream
  4. Review the push results. At the bottom, a "... deployed to Heroku" message will appear. Push Results

Done!

You've just cloned, modified, and deployed a brand new app.

See your changes

Learn more at the Heroku Dev Center

Using the Command Line:

Step 1. Setup your environment

  1. Install the Heroku Toolbelt.
  2. Install Maven.

Step 2. Login to Heroku

heroku login
Be sure to create, or associate an SSH key with your account.
$ heroku login
Enter your Heroku credentials.
Email: naaman@heroku.com
Password:
Could not find an existing public key.
Would you like to generate one? [Yn] Y
Generating new SSH public key.
Uploading SSH public key /Users/Administrator/.ssh/id_rsa.pub
Authentication successful.

Step 3. Clone the App

git clone -o heroku git@heroku.com:.git

Step 4. Makes some changes to the app

  1. Open src/main/java/com/example/services/TimeService.java in your favorite editor.
  2. To add a new resource path that supports specific time zones (e.g. GET /services/time/est for the time in Eastern Standard Time), add this method:
    @GET
    @Path("/{timezone}")
    public Time get(@PathParam("timezone") String timezone) {
        return new Time(TimeZone.getTimeZone(timezone.toUpperCase()));
    }
    Be sure to also add the necessary import statements:
    import javax.ws.rs.PathParam;
    import java.util.TimeZone;
    

Step 5. Make sure the app still compiles

mvn clean package

Step 6. Deploy your changes

  1. git commit -am "New changes to deploy"
  2. git push heroku master

Done!

You've just cloned, modified, and deployed a brand new app.

See your changes

Learn more at the Heroku Dev Center

REST Client

×