Container Application Development with Java

Quick Start Guide

Introduction

Java is a famous programming language. Compiled Java code can run on any platform with a Java Virtual Machine, so it's highly portable. This HowTo describes the steps to get a Container with a Java Virtual Machine in it.

To be able to start Java applications there must be a Java Virtual Machine and a set of class libraries. In this HowTo the Oracle Java SE will be used. Due to the "Oracle Binary Code License Agreement" it's not allowed to offer an already prepared container image. Creating a container with Oracle Java is quite easy:

Install a container on an M3 device

Use the web interface of your M3 device:

Now you should be able to ping the container. It's assumed the container gets bridged to "net1" and has the IP address 192.168.1.3/24. Open a console and try:


joe@pc ~/ ping 192.168.1.3

In case this is successful the next step is to establish an SSH connection to the container as user "root" with password "root":


joe@pc ~/ ssh root@192.168.1.3

Login by typing the password "root". It's highly recommended to change the password of root with the command "passwd".

Download and install Java

Oracle offers its JRE 8 (Java Runtime Environment) precompiled for ARMv7 within the JDK (Java Development Kit)

Run your first Java application

Create a file with the name "HelloWorld.java" on your PC:


joe@pc ~/ nano HelloWorld.java

Copy and paste this Code:
Create a file with the name "HelloWorld.java" on your PC:


public class HelloWorld
{
public static void main (String[] args)
{
System.out.println("Hello World!");
}
}

Store and exit the editor. Run the Java compiler, which will create a .class file containing the program, that the java virtual machine can handle:


joe@pc ~/ javac HelloWorld.java

Transfer the binary file HelloWorld.class file into the container:


joe@pc ~/ scp HelloWorld.class root@192.168.1.3:~

Log in to your container and start the application:


joe@pc ~/ ssh root@192.168.1.3
root@container_d4273e3d ~ $ java HelloWorld

Finished!

Your Java container is ready, you can use it as a template container for future Java projects. Done!