Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(examples): Introduce Hello in Java as example #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/hello-java17/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/rootfs/
/rootfs.cpio
/run-qemu*
/run-fc*
/kraft-run-*
/fc*.json
26 changes: 26 additions & 0 deletions examples/hello-java17/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM --platform=linux/x86_64 debian:bookworm AS build

RUN set -xe ; \
apt -yqq update ; \
apt -yqq install default-jre ; \
apt -yqq install default-jdk

WORKDIR /src

COPY ./Hello.java /src/Hello.java

RUN javac Hello.java

FROM scratch

COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY --from=build /lib/x86_64-linux-gnu/libstdc++.so.6 /lib/x86_64-linux-gnu/libstdc++.so.6
COPY --from=build /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6
COPY --from=build /usr/lib/x86_64-linux-gnu/libz.so.1 /usr/lib/x86_64-linux-gnu/libz.so.1
COPY --from=build /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/x86_64-linux-gnu/libgcc_s.so.1
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2

COPY --from=build /usr/lib/jvm/java-17-openjdk-amd64 /usr/lib/jvm/java-17-openjdk-amd64
COPY --from=build /usr/lib/jvm/java-17-openjdk-amd64/lib/libjli.so /lib/x86_64-linux-gnu/libjli.so

COPY --from=build /src/Hello.class /Hello.class
5 changes: 5 additions & 0 deletions examples/hello-java17/Hello.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
9 changes: 9 additions & 0 deletions examples/hello-java17/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spec: v0.6

name: hello-java

runtime: index.unikraft.io/unikraft.org/base:latest

rootfs: ./Dockerfile

cmd: ["/usr/lib/jvm/java-17-openjdk-amd64/bin/java", "Hello"]
4 changes: 4 additions & 0 deletions examples/hello-java17/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
IMAGE_NAME = unikraft-java
CMD = /usr/lib/jvm/java-17-openjdk-amd64/bin/java Hello

include ../../utils/bincompat/docker.Makefile
20 changes: 20 additions & 0 deletions examples/hello-java17/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Hello World on Java

This directory contains the definition to run a helloworld program with [Python3](https://www.python.org/) on Unikraft in binary compatibility mode.

Follow the instructions in the common `README.maintainers.md` file in the root of the repository to set up and configure the application.

## Quick Run

Use `kraft` to run the image:

```console
kraft run -M 512M
```

Once executed, it will run the `helloworld.py` script and print "Hello, World!".

## Scripted Run

Use the scripted runs, detailed in the `README.maintainers.md` file.
Once executed, scripts will run the `helloworld.py` script and print "Hello, World!".
4 changes: 4 additions & 0 deletions examples/hello-java17/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
networking: False
accel: True
memory: 1048
kerneldir: ../../kernels