Pablo Solar VilariƱo
2020-04-13 d29ca4b49b542d4b2f959a47ae70993514f154bf
Added Vert.X Simplest app (#6)

4 files added
177 ■■■■■ changed files
maven-simplest/Dockerfile 17 ●●●●● patch | view | raw | blame | history
maven-simplest/README.adoc 32 ●●●●● patch | view | raw | blame | history
maven-simplest/pom.xml 112 ●●●●● patch | view | raw | blame | history
maven-simplest/src/main/java/io/vertx/example/HelloWorldEmbedded.java 16 ●●●●● patch | view | raw | blame | history
maven-simplest/Dockerfile
New file
@@ -0,0 +1,17 @@
FROM openjdk:8-jre-alpine
ENV VERTICLE_FILE maven-simplest-3.9.0-fat.jar
# Set the location of the verticles
ENV VERTICLE_HOME /usr/verticles
EXPOSE 8080
COPY target/$VERTICLE_FILE $VERTICLE_HOME/
# Launch the verticle
WORKDIR $VERTICLE_HOME
ENTRYPOINT ["sh", "-c"]
CMD ["exec java -jar $VERTICLE_FILE"]
maven-simplest/README.adoc
New file
@@ -0,0 +1,32 @@
= Vert.x Simplest Maven project
This project shows a very simple hello world Vert.x project using Maven, which has a simple HTTP server which
simply returns "Hello World!" to every request.
In this example Vert.x is used embedded. I.e. we use the Vert.x APIs directly in our own classes rather than deploying
the code in verticles.
You can run or debug the example in your IDE by just right clicking the main class and run as.. or debug as...
The pom.xml uses the Maven shade plugin to assemble the application and all it's dependencies into a single "fat" jar.
To run with maven
    mvn compile exec:java
To build a "fat jar"
    mvn package
To run the fat jar:
    java -jar target/maven-simplest-3.9.0-fat.jar
(You can take that jar and run it anywhere there is a Java 8+ JDK. It contains all the dependencies it needs so you
don't need to install Vert.x on the target machine).
You can also run the fat jar with maven:
    mvn package exec:exec@run-app
Now point your browser at http://localhost:8080
maven-simplest/pom.xml
New file
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>io.vertx</groupId>
  <artifactId>maven-simplest</artifactId>
  <version>3.9.0</version>
  <properties>
    <!-- the main class -->
    <exec.mainClass>io.vertx.example.HelloWorldEmbedded</exec.mainClass>
  </properties>
  <dependencies>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-core</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>
  <build>
    <pluginManagement>
      <plugins>
        <!-- We specify the Maven compiler plugin as we need to set it to Java 1.8 -->
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <!--
    You only need the part below if you want to build your application into a fat executable jar.
    This is a jar that contains all the dependencies required to run it, so you can just run it with
    java -jar
    -->
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Main-Class>${exec.mainClass}</Main-Class>
                  </manifestEntries>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource>
                </transformer>
              </transformers>
              <artifactSet>
              </artifactSet>
              <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.4.0</version>
        <executions>
          <execution>
            <!-- run the application using the fat jar -->
            <id>run-app</id>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>java</executable>
              <arguments>
                <argument>-jar</argument>
                <argument>target/${project.artifactId}-${project.version}-fat.jar</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>staging</id>
      <repositories>
        <repository>
          <id>staging</id>
          <url>https://oss.sonatype.org/content/repositories/iovertx-3868/</url>
        </repository>
      </repositories>
    </profile>
  </profiles>
</project>
maven-simplest/src/main/java/io/vertx/example/HelloWorldEmbedded.java
New file
@@ -0,0 +1,16 @@
package io.vertx.example;
import io.vertx.core.Vertx;
/**
 * @author <a href="http://tfox.org">Tim Fox</a>
 */
public class HelloWorldEmbedded {
  public static void main(String[] args) {
    // Create an HTTP server which simply returns "Hello World!" to each request.
    Vertx.vertx().createHttpServer().requestHandler(req -> req.response().end("Hello World!\n")).listen(8080);
  }
}