One thing about Java applications is that you need to generate byte code
to execute it, and every Java developer knows that you should never commit
your byte code to source control because of the size (for pet-clinic, 500KB of sources become 40MB of compiled jars/wars). For this reason, with Stackato demo applications we generally recommend that Java developers do the extra step of compiling the bytecode before deployment.

With the preliminary support of Heroku Buildpacks in Stackato 1.2,
there's now a way to make compilation happen as part of the app deployment.

So let's explain both methods of deploying Java to Stackato.

Building it locally

The first way is to build the application before pushing to Stackato. This
method has been available all along in Stackato when using the 'java_web' and
'spring' frameworks:

However, if your application uses a database like pet-clinic does, and if there are maven tests on this database, you will need to set up a local database to pass these tests. You could use the '-Dmaven.test.skip' argument to skip tests, but this is not recommended.

maven clean package -Dmaven.test.skip=true

It would be nice to run these tests against the actual database we'll be using. We can do that using the 'buildpack' framework.

Using a Java Buildpack

Heroku Buildpack support is new in Stackato 1.2. Heroku introduced this system as a way for users to add custom frameworks to their PaaS. Stackato has other ways of customizing the application environment, but buildpacks have become popular, so we decided to emulate them in the Stackato environment.

In the case of our demo Java application, the Java buildpack allows the application bytecode to be built on Stackato instead of on your local machine. The Java buildpack also includes OpenJDK if you want to run a simple java application.

For the pet-clinic application for example, we need a Java-based server to run the application. To do that, we will use Jetty. Jetty is a light Java application server. It includes a Jetty Runner. The good thing about Jetty is that you can run your Java web application with a simple command just by providing the war file:

java -jar jetty-runner.jar application.war

Advantages of using the buildpack framework?

You don't need Maven on your local machine

The application builds on the PaaS instead of on your machine

You don't have to push all the byte code

You don't need to set up a special environment for tests.

You don't have to rely on Tomcat. You can specify another web server (such as Jetty or Netty).

How does it work with Stackato?

It is really easy! You only need to modify three files.

First, in 'stackato.yml' you will need to define the framework type and to
provide the buildpack url. Here is the pet-clinic stackato.yml: