pom.xml
1<?xml version="1.0" encoding="UTF-8"?> 2<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 3 xmlns="http://maven.apache.org/POM/4.0.0" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 5 <modelVersion>4.0.0</modelVersion> 6 <groupId>net.loyin.study</groupId> 7 <artifactId>vertx</artifactId> 8 <version>1.0-SNAPSHOT</version> 9 <properties> 10 <vertx.version>3.8.1</vertx.version> 11 </properties> 12 <dependencyManagement> 13 <dependencies> 14 <dependency> 15 <groupId>io.vertx</groupId> 16 <artifactId>vertx-stack-depchain</artifactId> 17 <version>${vertx.version}</version> 18 <type>pom</type> 19 <scope>import</scope> 20 </dependency> 21 <dependency> 22 <groupId>io.vertx</groupId> 23 <artifactId>vertx-stack-depchain</artifactId> 24 <version>${vertx.version}</version> 25 <type>pom</type> 26 <scope>import</scope> 27 </dependency> 28 </dependencies> 29 </dependencyManagement> 30 <dependencies> 31 <dependency> 32 <groupId>io.vertx</groupId> 33 <artifactId>vertx-core</artifactId> 34 <version>${vertx.version}</version> 35 </dependency> 36 <dependency> 37 <groupId>io.vertx</groupId> 38 <artifactId>vertx-web</artifactId> 39 <version>${vertx.version}</version> 40 </dependency> 41 <dependency> 42 <groupId>io.vertx</groupId> 43 <artifactId>vertx-web</artifactId> 44 </dependency> 45 </dependencies> 46 <build> 47 <plugins> 48 <plugin> 49 <artifactId>maven-shade-plugin</artifactId> 50 <version>3.1.0</version> 51 <executions> 52 <execution> 53 <phase>package</phase> 54 <goals> 55 <goal>shade</goal> 56 </goals> 57 <configuration> 58 <transformers> 59 <transformer 60 implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 61 <manifestEntries> 62 <main-class>io.vertx.core.Starter</main-class> 63 <main-verticle>net.loyin.study.vertx.Application</main-verticle> 64 </manifestEntries> 65 </transformer> 66 </transformers> 67 <artifactSet/> 68 <!-- <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>--> 69 </configuration> 70 </execution> 71 </executions> 72 </plugin> 73 <plugin> 74 <artifactId>maven-compiler-plugin</artifactId> 75 <version>3.2</version> 76 <configuration> 77 <source>1.8</source> 78 <target>1.8</target> 79 <encoding>UTF-8</encoding> 80 </configuration> 81 </plugin> 82 </plugins> 83 </build> 84 <profiles> 85 <profile> 86 <id>jdk18</id> 87 <activation> 88 <activeByDefault>true</activeByDefault> 89 <jdk>1.8</jdk> 90 </activation> 91 <properties> 92 <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> 93 <maven.compiler.source>1.8</maven.compiler.source> 94 <maven.compiler.target>1.8</maven.compiler.target> 95 </properties> 96 </profile> 97 </profiles> 98</project>
启动类:
1package net.loyin.study.vertx; 2 3import io.vertx.core.AbstractVerticle; 4import io.vertx.core.Vertx; 5import io.vertx.ext.web.Router; 6 7public class Application extends AbstractVerticle { 8 9 public static void main(String[] args){ 10 Vertx vertx=Vertx.vertx(); 11 vertx.deployVerticle(new Application()); 12 } 13 @Override 14 public void start(){ 15 Router router=Router.router(vertx); 16 router.route().handler(routingContext->{ 17 routingContext.response().putHeader("content-type", "text/html").end("Hello World!"); 18 }); 19 vertx.createHttpServer().requestHandler(router).listen(8800); 20 } 21}
Dockerfile
1FROM java:8 2VOLUME /tmp 3ADD ./target/vertx-1.0-SNAPSHOT.jar app.jar 4RUN bash -c 'touch /app.jar' 5EXPOSE 8800 6ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","app.jar"]