Skip to content

Static Web Site with Maven

rhart edited this page Nov 2, 2012 · 12 revisions

This is an example of how to create a static web site with vert.x and Maven.

Pre Requisites

  • This example uses the out-of-the-box web-server module so you need a local vert.x installation See Here

Steps

  1. Create a folder for your web site, mine will be called "mywebsite".
  2. Create a folder for your web pages. Following Maven conventions mine will be "mywebsite/src/main/webapp".
  3. Create a file called index.html in the web pages folder with the following content:
    <html><body>Hello World!</body></html>
  4. Create a folder for a vert.x config file. Following Maven conventions mine will be "mywebsite/src/main/resources".
  5. Create a file called myapp.conf in the resources folder with the following content:
    { "web_root": "src/main/webapp", "port": 8081 }
  6. Create a file called POM.xml in the "mywebsite" folder with the following content but replacing vertxHomeDirectory with your vert.x home directory:

<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>org.me</groupId>
	<artifactId>mywebsite</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<build>
		<plugins>
			<plugin>
				<groupId>org.vertx</groupId>
				<artifactId>vertx-maven-plugin</artifactId>
				<version>1.3.0.1-RELEASE</version>
				<configuration>
					<vertxHomeDirectory>C:/vert.x/vert.x-1.3.0.final</vertxHomeDirectory>
					<verticleName>web-server</verticleName>
			                <configFile>src/main/resources/myapp.conf</configFile>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>org.vertx</groupId>
			<artifactId>core</artifactId>
			<version>1.3.0.final</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.vertx</groupId>
			<artifactId>platform</artifactId>
			<version>1.3.0.final</version>
			<scope>provided</scope>
		</dependency>
	</dependencies>
    </project>

  1. Run mvn vertx:run
  2. Browse to http://localhost:8081 and see your page.
Clone this wiki locally