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.
[sourcecode language=”xml”]
<build>
<finalname>testWebApp</finalname>
<plugins>
<plugin>
<artifactid>maven-compiler-plugin</artifactid>
<configuration>
<source>1.6
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
[/sourcecode]
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.
[sourcecode language=”html”]
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
[/sourcecode]
Now, add the jetty plugin in your pom.xml.
[sourcecode language=”xml”]
<plugin>
<groupid>org.mortbay.jetty</groupid>
<artifactid>maven-jetty-plugin</artifactid>
<version>6.1.17</version>
</plugin>
[/sourcecode]
Now run the jetty server
mvn jetty:run
Then go to localhost:8080/testWebApp in your browser. The following will be the output.