Jetty Hello World Eclipse

Jetty Hello World Eclipse

If you have just stared with Jetty want to have a quick look how it works with Eclipse please follow steps below:

  • Create maven project name: JettyHelloWold (If you are not sure how to create maven project in eclipse please follow steps from this tutorial http://techiworks.com/create-maven-project-eclipse
  • Below is sample default project structure that can be download from link mentioned in the bottom of this page:

Jetty Hello World Eclipse

  • Add below dependencies in pom.xml:
<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>com.javahonk</groupId>
  <artifactId>JettyHelloWorld</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>JettyHelloWorld Maven Webapp</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>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>JettyHelloWorld</finalName>
    <plugins>
      <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.3.0.RC2</version>
      </plugin>
    </plugins>
  </build>
</project>
  • By default maven search settings.xml in C:\Users\user_name\.m2 directory please add below setting.xml file in this directory:

Note: Only below extra pluginGroups you will have to add in default settings.xml file because when you run jetty command it searches this plugin group:

<pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
	<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
  • To run jetty from command prompt you will have to set up JAVA_HOME,M2_HOME and path to environment variable.

Note: As you see below we are setting these in User Variables not System Variable because if you are working in big company they give admin permission to local computer so that you can not change environment system variable.

Jetty Hello World Eclipse

Jetty Hello World Eclipse

  • Once all setup is done go to command prompt and type “mvn jetty:run” command:

Jetty Hello World Eclipse

  • You will see below on console:
C:\JavaHonk\eclipse_luna\workspace\JettyHelloWorld>mvn jetty:run
[INFO] Scanning for projects...
[WARNING] The POM for org.eclipse.jetty:jetty-maven-plugin:jar:9.3.0.RC2 is missing, no dependency information ava
lable
[WARNING] Failed to retrieve plugin descriptor for org.eclipse.jetty:jetty-maven-plugin:9.3.0.RC2: Plugin org.ecli
se.jetty:jetty-maven-plugin:9.3.0.RC2 or one of its dependencies could not be resolved: Failure to find org.eclips
.jetty:jetty-maven-plugin:jar:9.3.0.RC2 in https://repo.maven.apache.org/maven2 was cached in the local repository
 resolution will not be reattempted until the update interval of central has elapsed or updates are forced
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building JettyHelloWorld Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.eclipse.jetty:jetty-maven-plugin:jar:9.3.0.RC2 is missing, no dependency information ava
lable
[WARNING] Failed to retrieve plugin descriptor for org.eclipse.jetty:jetty-maven-plugin:9.3.0.RC2: Plugin org.ecli
se.jetty:jetty-maven-plugin:9.3.0.RC2 or one of its dependencies could not be resolved: Failure to find org.eclips
.jetty:jetty-maven-plugin:jar:9.3.0.RC2 in https://repo.maven.apache.org/maven2 was cached in the local repository
 resolution will not be reattempted until the update interval of central has elapsed or updates are forced
[INFO]
[INFO] >>> jetty-maven-plugin:8.1.16.v20140903:run (default-cli) > test-compile @ JettyHelloWorld >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ JettyHelloWorld ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ JettyHelloWorld ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ JettyHelloWorld ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\JavaHonk\eclipse_luna\workspace\JettyHelloWorld\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ JettyHelloWorld ---
[INFO] No sources to compile
[INFO]
[INFO] <<< jetty-maven-plugin:8.1.16.v20140903:run (default-cli) < test-compile @ JettyHelloWorld <<<
[INFO]
[INFO] --- jetty-maven-plugin:8.1.16.v20140903:run (default-cli) @ JettyHelloWorld ---
[INFO] Configuring Jetty for project: JettyHelloWorld Maven Webapp
[INFO] webAppSourceDirectory not set. Defaulting to C:\JavaHonk\eclipse_luna\workspace\JettyHelloWorld\src\main\webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = C:\JavaHonk\eclipse_luna\workspace\JettyHelloWorld\target\classes
[INFO] Context path = /
[INFO] Tmp directory = C:\JavaHonk\eclipse_luna\workspace\JettyHelloWorld\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = file:/C:/JavaHonk/eclipse_luna/workspace/JettyHelloWorld/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = C:\JavaHonk\eclipse_luna\workspace\JettyHelloWorld\src\main\webapp
[INFO] jetty-8.1.16.v20140903
[INFO] No Transaction manager found - if your webapp requires one, please configure one.
[WARNING] !RequestLog
[INFO] Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server
  • As you see above server started on localhost at port 8080 where application is accessible. Type below in browser you will see result:

Jetty Hello World Eclipse

download Download Project: JettyHelloWorld

One thought on “Jetty Hello World Eclipse”

Leave a Reply

Your email address will not be published. Required fields are marked *