Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy Java App on Heroku which depends on my own Maven artifacts

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.

like image 748
user1615303 Avatar asked Aug 21 '12 20:08

user1615303


People also ask

Can I host a Java application on Heroku?

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.

Does Heroku support Maven?

Heroku provides support for Maven Wrapper, which is the recommend mechanism for defining a Maven version.

How do I deploy an existing app to Heroku?

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.


2 Answers

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:

  1. Install Anvil:

    heroku plugins:install https://github.com/ddollar/heroku-anvil

  2. 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

  3. 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

  4. Create the Heroku app:

    heroku create

  5. Use Anvil to build with the null buildpack and release to the app:

    heroku build -b https://github.com/ryandotsmith/null-buildpack.git -r

like image 174
ryanbrainard Avatar answered Sep 28 '22 16:09

ryanbrainard


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.

like image 36
yegor256 Avatar answered Oct 01 '22 16:10

yegor256