How to package custom code


You can extend RESTHeart by implementing custom extensions, such as Application Logic Handlers and Request Hooks. As RESTHeart is a Java application, to package custom code you usually use Maven or any Maven-compatible tool, such as Gradle.

A basic knowledge of Maven is required to follow this guide.

RESTHeart is available as a Maven artifact and so it can be included in your own custom POM. Here you can see examples of how to configure dependencies with different build tools.

To add RESTHeart JAR as a dependency to your pom.xml, add this fragment:


Create a Uber jar

The Maven Shade plugin provides the capability to package the artifacts in an single, self-executable JAR file, which includes all necessary dependencies.

                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

Now you can run mvn package or mvn install.

Remember that if you have written any integration test, you’ll probably need a running MongoDB instance on localhost:27017 to exceute them succesfully. To create and run end to end tests, from the REST API down to the database, we recommend having a look at Karate DSL.

The above configuration will produce a single JAR file whose name is the artifactId, for instance foo.jar. This jar will include both your custom code and RESTHeart. You can start the customized RESTHeart with:

$ java -server -jar foo.jar conf.yml