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:
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
Oracle offers its JRE 8 (Java Runtime Environment) precompiled for ARMv7 within the JDK (Java Development Kit)
Download the version for Linux ARM 32 Hard Float ABI (click jdk-8-XXXX-linux-arm32-vfp-hflt.tar.gz")
Unpack the downloaded image on your PC
joe@pc ~/ tar xf jdk-8u144-linux-arm32-vfp-hflt.tar.gz
Enter the "jre" directory of the extracted directory:
joe@pc ~/ cd jdk1.8.0_144/jre
Transfer all files into the container on the M3 device:
joe@pc ~/ scp -r * root@192.168.1.3:/
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
Your Java container is ready, you can use it as a template container for future Java projects. Done!