Add your Java web application to Jetty Server

What is Jetty Server ?

Jetty  is a pure Java-based HTTP server and servlet container (application server). Jetty is a free and open source project under the Apache 2.0 License. Jetty deployment focuses on creating a simple, efficient, embeddable and pluggable web server. Jetty’s small size makes it suitable for providing web services in an embedded Java application. It also offers support for Web Sockets, OSGi, JMX, JNDI, JASPI, AJP, and other Java technologies. ( Wikipedia).

Lets first create a sample web app using maven. Then deploy it to jetty server using maven-jetty plugin.

Generate the testWebApp using following command in the cmd.

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp -DartifactId=testWebApp -DgroupId=net.supun.maven -Dversion=1.0-SNAPSHOT -Dpackage=net.supun.maven

Here is the output.

Then open the pom.xml file and add the following lines to it.


<build>

<finalname>testWebApp</finalname>
 <plugins>
 <plugin>
 <artifactid>maven-compiler-plugin</artifactid>
 <configuration>
 <source>1.6
 <target>1.6</target>
 </configuration>
 </plugin>
 </plugins>
 </build>

Then compile and install the project using Maven.
mvn compile
mvn test
mvn install

Then the file named index.jsp has created with the following content.

<html>
<body>
<h2>Hello World!</h2>
</body>
</html>

Now, add the jetty plugin in your pom.xml.

<plugin>
 <groupid>org.mortbay.jetty</groupid>
 <artifactid>maven-jetty-plugin</artifactid>
 <version>6.1.17</version>
 </plugin>

Now run the jetty server
mvn jetty:run
Then go to localhost:8080/testWebApp in your browser. The following will be the output.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s