Skip to content

Instantly share code, notes, and snippets.

@naaman
Created June 19, 2012 22:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naaman/2956915 to your computer and use it in GitHub Desktop.
Save naaman/2956915 to your computer and use it in GitHub Desktop.
Updated JDK Support

Updated JDK Support

Heroku now offers beta support for OpenJDK 7, as well as an updated version of OpenJDK 6. Support for both JDKs are available in a new buildpack. OpenJDK 6 is still the default, but the version has been increased to u25 from u20 -- changes for u20-u25 can be found on Oracle's changelist blog. OpenJDK 7 can be enabled by configuring your pom.xml. Currently, only maven builds are supported with this update.

This update has no impact on any running applications. If you choose not to use this buildpack, your applications will continue to use OpenJDK 6u20.

Contents

Pre-requisites

Getting Started

Note: this is beta software. It is strongly recommended you try this on a non-production application.

  1. In a terminal, change directories to your app. To verify, you should see output similar to:

    $ ls
    Procfile  pom.xml  src
    
  2. Configure Heroku to use the new JDK support:

    For new applications

    heroku create -s cedar --buildpack git://github.com/naamannewbold/heroku-buildpack-java-jdk7.git

    For existing applications

    heroku config:add BUILDPACK_URL=git://github.com/naamannewbold/heroku-buildpack-java-jdk7.git

    heroku config:add PATH="/app/.jdk/bin:/usr/local/bin:/usr/bin:/bin"

  3. Configure your pom.xml to specify the source and target Java version using the maven-compiler-plugin:

    For JDK 6:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
    </plugin>

    For JDK 7:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>

    The version of the JDK is chosen based on the following order of operations:

    • An effective pom is generated (i.e. mvn help:effective-pom) and the maven-compiler-plugin configuration is parsed.
    • If the target is specified, the target version is used.
    • If the source is specified, the source version is used.
    • Otherwise, the default (1.6) is used.
  4. Commit your changes and push to Heroku:

    git add pom.xml
    git commit -m "Add version of the JDK"
    git push heroku master
    

    Your build output will begin with:

-----> Heroku receiving push -----> Fetching custom buildpack... done -----> Java app detected -----> Installing Maven 3.0.3... done -----> Detecting JDK version...1.6 detected -----> Installing JDK 1.6... done -----> executing mvn -B -Duser.home="/tmp/build_c8q3p41ai7a7" -Dmaven.repo.local="/app/tmp/repo.git/.cache/.m2/repository" -s "/app/tmp/repo.git/.cache"/.m2/settings.xml -DskipTests=true clean install [INFO] Scanning for projects... [INFO]
[INFO] ------------------------------------------------------------------------ [INFO] Building java-app 0.1 [INFO] ------------------------------------------------------------------------ ```

Slug Size Limit

Prior to this update, slug sizes were limited to 100mb. The JDK is now stored as part of your slug, which means approximately 40mb more in your slug. As a result, the slug size limit has been increased to 200mb to allow for the JDK and an additional buffer should other system dependencies be required. It is still a good practice to keep slug sizes small. Your slug size appears at the end of a build, or in heroku apps:info.

Feedback

If you have any feedback, please feel free to send a pull request, or log an issue. When sending pull requests, please review the repo's readme and consider writing tests where applicable. When logging issues, please include examples where possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment