- Details
- Written by: Stanko Milosev
- Category: Jetty
- Hits: 5279
To start simple Jetty server with Maven, download and install Maven, after that create and import project (in my case I created project in C:\Users\myUserName\Documents\myJetty\my-firstJettyTest) as I already explained here. Open pom.xml, and it should look like:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myJetty</groupId>
<artifactId>my-firstJettyTest</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-firstJettyTest</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-websocket</artifactId>
<version>8.1.12.v20130726</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.12.v20130726</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.11.v20130520</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopPort>8005</stopPort>
<stopKey>STOP</stopKey>
<contextPath>/</contextPath>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Then open command line in same folder where your project is, and you can execute:
mvn jetty:run
After that in your browser write something like: 127.0.0.1:8080 - Jetty by default starts on port 8080
In my case, I have created one index.html file and I place it here:
C:\Users\myUserName\Documents\myJetty\my-firstJettyTest\src\main\webapp