Heroku supports deployment of Java apps based on Maven
They also give advice for app deployment if a lib is needed that is not available in a public maven repository
But: I have two Maven projects, where one depends on the other one. When I locally mvn install the dependent artifact I can mvn package the other one and everything works fine. However, I cannot push it to heroku, because heroku can't access my local mvn repo.
What can I do? Will it be necessary to setup a private maven repo accessible to heroku on the web (e.g. artifactory) or are there any other ways to deploy such an app with a custom dependency on heroku?
Thanks.
You can deploy any Java application on Heroku. It is not limited to JEE or other frameworks. You can deploy Java web applications packaged as WAR files using WAR deployment or you can deploy Maven based Java projects of any kind using the git versioning system.
Heroku provides support for Maven Wrapper, which is the recommend mechanism for defining a Maven version.
To deploy your app to Heroku, use the git push command to push the code from your local repository's main branch to your heroku remote. For example: $ git push heroku main Initializing repository, done.
There is an alternate deployment path for Heroku called Anvil that might help here. With this path, you would build everything locally with any private libs you need and copy all dependencies into your target directory, and then use Anvil to build and release the whole thing to your Heroku app. By default, Anvil will detect your app as Java and try to build it again, but you can override this by specifiying the null buildpack, which tells it to take your files as is because you already did the build locally. This is probably better shown with an example:
Install Anvil:
heroku plugins:install https://github.com/ddollar/heroku-anvil
Clone this example app that already has copy-dependencies
configured in its pom.xml
. You would need to configure this in your own app:
git clone git://github.com/heroku/template-java-jaxrs.git
Go into the dir and build the app, which will run copy-dependencies
. This is critical because you need all your dependencies in your app's target
dir, not in ~/.m2/repository
so Heroku will be able to find them:
mvn package
Create the Heroku app:
heroku create
Use Anvil to build with the null buildpack and release to the app:
heroku build -b https://github.com/ryandotsmith/null-buildpack.git -r
Take a look how we do it with a live open source web app: pom.xml. The app is deployed to Heroku using Maven and Ant. We automatically do git clone
, then copy new files into the folder, and then do git commit && git push
. What's important is that we use maven-invoker-plugin
in order to download artifacts inside the Heroku slug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With