GithubHelp home page GithubHelp logo

sangrealwar / helloworld-java-9 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paulsandoz/helloworld-java-9

0.0 0.0 0.0 52 KB

Hello World example using Maven with Java 9

Shell 53.29% Batchfile 40.24% Java 6.46%

helloworld-java-9's Introduction

Hello World with Java 9 and Docker

A simple maven project generated from the using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) and updated to declare the maven compiler source and target for Java 9.

Example Docker files are also present for building Docker images containing a JDK 9 distribution.

Pre-requisites

To experiment download the following and place in the top-level directory:

Build Images and Run Containers

Build a Docker image with Alpine Linux and JDK 9:

docker build -t jdk-9-alpine -f jdk-9-alpine.Dockerfile .

Build a Docker image with Debian slim and JDK 9:

docker build -t jdk-9-debian-slim -f jdk-9-debian-slim.Dockerfile .

Run the docker image to enter into the Java REPL (jshell):

docker run -it --rm jdk-9-debian-slim

List the Java modules in JDK 9:

docker run -it --rm jdk-9-debian-slim java --list-modules

Build the simple Java application with a local distribution of JDK 9:

mvnw package

Build a Docker image containing the simple Java application based of the Docker image jdk-9-debian-slim:

docker build -t helloworld-jdk-9 -f helloworld-jdk-9.Dockerfile .

Run the java dependency tool jdeps on the application jar file:

docker run -it --rm helloworld-jdk-9 jdeps --list-deps /opt/helloworld/helloworld-1.0-SNAPSHOT.jar

Create a custom Java runtime that is small and only contains the java.base module: (See also the script create-minimal-java-runtime.sh):

docker run --rm \
  --volume $PWD:/out \
  jdk-9-debian-slim \
  jlink --module-path /opt/jdk-9/jmods \
    --verbose \
    --add-modules java.base \
    --compress 2 \
    --no-header-files \
    --output /out/target/openjdk-9-base_linux-x64

Build a Docker image containing the simple Java application based of the Docker image debian:slim and the custom Java runtime previous created:

docker build -t helloworld-jdk-9-base -f helloworld-jdk-9-base.Dockerfile .

List the modules in custom Java runtime:

docker run -it --rm helloworld-jdk-9-base java --list-modules

Run the docker images:

docker run -it --rm helloworld-jdk-9

docker run -it --rm helloworld-jdk-9-base

Compare sizes:

docker images

helloworld-java-9's People

Contributors

paulsandoz avatar arun-gupta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.