Getting your SBT-built Java project onto Heroku
I love Heroku for quickly deploying and testing your applications. The free usage tier makes it no cost for simple applications, and the Git Push To Deploy mechanism is a great way to test your build environment isn’t using cached resources.
If you’ve got a DropWizard 0.7.x service or similar built using SBT 0.13.x, and you deploy it to Heroku you may encounter the following error message:-
[error] Not a valid command: stage (similar: last-grep, set, last) [error] Not a valid project ID: stage [error] Expected ':' (if selecting a configuration) [error] Not a valid key: stage (similar: state, target, tags) |
The fix to this is to use the SBT Native Packager.
At the bottom of your ./project/plugins.sbt file, add
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.8.0") |
In your ./build.sbt file, add at the top
import NativePackagerKeys._ packageArchetype.java_application |
packageArchetype.java_application
and change your ./Procfile to be
web target/universal/stage/bin/**your_project_name** -Ddw.server.connector.port=$PORT server config/local.yml |
with your ./config/local.yml file looking something like:-
server: type: simple applicationContextPath: / adminContextPath: /admin connector: type: http port: 8080 |
This configuration binds the Admin and normal serving ports together because Heroku only allows you to bind to the Heroku-specified $PORT.
Push using Git and you should be up and running. (This is especially useful if you’re using an automated build tool such as Jenkins).
0 Comments on “Getting your SBT-built Java project onto Heroku”