How to deploy Java apps on Divio
Developer Tools

Java Apps: Deploy on Divio

Java remains an evergreen technology choice for building modern enterprise applications. This article will examine how the Divio platform is especially well-suited to building and managing Java apps.

Thomas Bailey

Thomas Bailey

Marketing

Divio recently added support for Java, a mainstay for developers for over twenty years and counting. The most recent yearly Stackoverflow developer reports places Java as the sixth most commonly used programming language. While the application of Java has changed, its legacy and vibrant developer community suggest it will remain a top choice, particularly for building secure and robust enterprise applications.

The initial Java proposition and vision was for a language that could run anywhere and on anything when accompanied by a suitable platform configuration. Java achieves this using a virtual machine (Java VM)  that runs interpreted code. Wherever the Java VM  exists, Java applications can conceptually run, alleviating the need to build apps for specific platforms.  Before Android, early mobile phones typically included a Java VM with a limited and specialised set of features that opened the possibilities of what we now consider app stores.

Java tends to be used as an all-encompassing term, mixing the language with the platform. However, Java is delivered primarily in two platform flavours to meet different needs and device types.

Java Standard Edition (Java SE) bundles Java with the features and capabilities to build cross-platform desktop apps, including sound and graphics. Perhaps the most widely known is Minecraft, the hugely popular sandbox game. Java SE, also known as a runtime, is used to launch and run Java apps without the components to develop Java applications.

Java Enterprise Edition (Java EE) is built upon Java SE with added features and technologies that make it suitable for large, scaleable web apps. Important to note is Java EE is a specification that different vendors can implement. Perhaps the most prominent is the “GlassFish” application server, offering a Java EE-compliant environment to run Java EE applications. This means that it supports the Java EE specification and is considered compliant. While a topic of debate, application servers that are Java EE compliant should enable apps to be migrated across without code change.

Common to both is the Java Development Kit (JDK), used to compile or build Java source, which is then run upon Java SE or EE and can use the available features.

As with most technologies, frameworks emerge to simplify the development of everyday tasks to reduce repeat code, shorten development times and increase efficiency.

Enter Spring (and Spring Boot)

The Spring framework has become synonymous with Java development. It provides open-source infrastructure and tools for building Java apps quicker, with commonly required functionality and features that would otherwise need to be recreated.

The Java EE specification includes Enterprise Java Beans (EJBs) – server-side components or “beans” that encapsulate business logic and are designed to run on an application server.

The Spring framework was initially created with the goal of simplifying the configuration and setup of EJBs, alleviating the need for a heavy-weight application server. It uses a very modular approach to application development, allowing developers to choose the specific components they need for their projects – such as database access or authentication/authorisation features.

The Divio Java stack includes Spring Boot as a convenient ready-to-use template – an opinionated configuration of the Spring framework that simplifies the development of stand-alone, production-ready Spring applications and comes with a lightweight application server.

Empowering Java Development

The Divio platform handles all technology stacks in a consistent manner – building and deploying “containers” locally and when deployed to the Divio cloud to provide an identical environment. This makes it possible to quickly set up a local development environment, work locally, and deploy when ready by packaging and running apps in lightweight, self-contained environments. 

In contrast to non-container-based development, development environments are created on each working developer machine, installing and configuring the required software, managing versioning conflicts and updates whilst trying to keep teams and the changes being made synchronised. Specific changes must be carried across to a cloud or server-based environment and applied during deployment amongst team members.

Java apps, by their nature, have multiple dependencies. Ensuring consistency across different environments, including matching Java versions, libraries, and configurations, can be challenging, especially when multiple developers and teams are involved.

Through using containers, Java apps become self-contained and portable, with everything required included. 

The Divio CLI (command line tool) and the Divio Control Panel work in conjunction to facilitate initial container creation, setting up a local environment and deploying to the cloud. 

The Divio CLI works hand-in-hand with Docker, a desktop container platform used when working locally. Developers can use both CLI tools together to build and deploy containers for their apps.

Development teams become autonomous to develop and securely deploy Java apps without requiring a typical DevOps function and eliminating the operational overhead associated with managing infrastructure.

This represents productivity gains and accelerated development cycles as developers can focus more on app development and business logic rather than repeatedly setting up and configuring underlying infrastructure.

Scaling Up to Meet Demand — Just in Time

Calculating cloud infrastructure costs ahead of time is generally an exercise in best-effort predictions, with plenty of accounts of run-away cloud costs as usage spirals. Bugs or issues that cause unnecessary resource consumption can be unforeseen expensive accidents.

Java apps can be particularly memory-intensive due to the Java VM and the nature of how the memory management system (or garbage collection) works. Essentially the Java VM keeps track of memory usage and cleans up periodically. Excessive memory consumption through inefficient code can lead to performance slowdown, increasing infrastructure costs.

The Divio platform offers opinionated configurations with sensible default settings, giving a fixed and predictable monthly cost upfront. Tools such as Metrics provide an easy way to ascertain app performance and consumption, allocating more resources or refactoring apps accordingly. 

The Divio platform orchestrates large amounts of cloud resources, which can be allocated to address apps that may be misbehaving or consume a large number of resources, ensuring performance is maintained.

Infrastructure Built-in

The Divio platform automatically provisions and includes commonly used services, conceptually treating apps as one entity rather than multiple services connected through different roles and accounts. 

An important consideration is maintaining the portability of Java apps – upholding the promise of “run anywhere” and avoiding binding to vendor-specific features. The Divio approach breaks dependencies on the cloud that the Divio platform orchestrates, using best practices to abstract away cloud-specific features.

By default, a Postgres database is preconfigured and automatically coupled with Java apps when working locally and on the cloud. Services, such as object storage or a MySQL database, can be added on-demand from the Divio Control Panel without the usual overhead associated with set-up and configuration.

Environmental variables are pre-populated and used to hold keys and values to the available services, following a best practices approach for portable apps.

Using environmental variables pre-populated by the Divio platform is especially well-suited to Spring Boot. Spring-based Java apps move app configuration to its own file, making it possible to configure services with changing code using environmental variables.

Managing and versioning Java configuration files across different environments and deployments can be cumbersome. Ensuring consistency and managing configuration changes effectively is crucial for maintaining a reliable and scalable infrastructure. 

The Divio platform uses Git by default to provide version control for project resources, including Java configuration files, ensuring that local developer environments are always consistent.

Get Started with Java on the Divio Platform

The Divio platform introduces the concept of technology stacks to simplify project creation – a core technology, such as Java, additional components and a boilerplate. 

The Divio Java stack includes an up-to-date release of the Eclipse Adoptium flavour of OpenJDK, a project that provides supported pre-built versions of the OpenJDK. The OpenJDK results from an initiative to provide Java under an open-source license, making it available to various platforms and operating systems. 

Additional components are typically middleware or frameworks designed to handle everyday tasks and provide standardised services to simplify development. For Java, this is Spring Boot.

Finally, using the middleware or framework, a boilerplate is a minimal “barebones” application. Boilerplates are helpful to quickly evaluate a technology or for use as a foundation to customise and tweak.

The Divio Java technology stack provides a starting point to use as a reference to build a Spring Boot-based app or to move an existing Spring Boot app to the Divio platform to get the benefits that the Divio platform can provide immediately.

Bringing the Benefits of the Divio Platform to Java

The Divio platform includes support for Java, providing enterprise-grade multi-cloud capability, one-click service deployment and powerful developer tools. By bringing Java apps to the Divio platform, development teams can become more autonomous and effective, eliminating the costs and DevOps demands usually associated with Java apps in the cloud.

Contact us to learn more!

Stay updated! Connect with our LinkedIn and X/Twitter networks for exclusive insights, as well as be the first in the know about our most recent blogs.