Browse Source

Add Maven project

master
Florian Latifi 3 years ago
parent
commit
68ea3dc23d
3 changed files with 106 additions and 0 deletions
  1. +85
    -0
      pom.xml
  2. +8
    -0
      src/main/docker/Dockerfile
  3. +13
    -0
      src/main/java/at/flortsch/example/docker/Main.java

+ 85
- 0
pom.xml View File

@@ -0,0 +1,85 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>at.flortsch</groupId>
<artifactId>maven-docker-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Maven Docker Example</name>
<description>Using a template and the Maven Resources Plugin to generate a Dockerfile which is used on the Docker CLI to build a Docker image.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<application.mainclass>at.flortsch.example.docker.Main</application.mainclass>
<application.dependencies>lib</application.dependencies>
<application.workdir>application</application.workdir>
</properties>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>3.4.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/${application.dependencies}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${application.dependencies}</classpathPrefix>
<mainClass>${application.mainclass}</mainClass>
<!-- match with base version string naming -->
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<directory>src/main/docker</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

+ 8
- 0
src/main/docker/Dockerfile View File

@@ -0,0 +1,8 @@
FROM openjdk:8-jre-alpine

WORKDIR ${application.workdir}
COPY ${application.dependencies} ${application.dependencies}
COPY ${project.build.finalName}.jar ${project.build.finalName}.jar

ENTRYPOINT ["/usr/bin/java", "-jar", "${project.build.finalName}.jar"]
EXPOSE 8080

+ 13
- 0
src/main/java/at/flortsch/example/docker/Main.java View File

@@ -0,0 +1,13 @@
package at.flortsch.example.docker;

import io.vertx.core.Vertx;

public class Main {

public static void main(String[] args) {
Vertx.vertx().createHttpServer().requestHandler(request -> {
request.response().putHeader("content-type", "text/html").end("<h1>Hello World!</h1>");
}).listen(8080);
}

}

Loading…
Cancel
Save