Jetty actual combat embedded Jetty run Web App__web

Source: Internet
Author: User
Tags glassfish

This article address: http://blog.csdn.net/kongxx/article/details/7237034

To say embedded run jetty, the most common should also be to run a standard war file or specify a WebApp directory.

0. First you need to add the Jetty Runtime WebApp dependency package, the following is a complete Pom.xml file

<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.google.code.garbagecan.jettystudy</groupId> < Artifactid>jettystudy</artifactid> <packaging>jar</packaging> <version>1.0-snapshot
		</version> <name>jettystudy</name> <url>http://maven.apache.org</url> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <inherited>true </inherited> <version>2.3.1</version> <configuration> <source>1.6</source&gt
					; <target>1.6</target> <debug>true</debug> </configuration> </plugin> < /plugins> </build> <dependencies> <!--SPRing support--> <dependency> <groupId>org.springframework</groupId> <artifactid>spring& Lt;/artifactid> <version>2.5.6</version> </dependency> <!--Jetty--> <dependenc Y> <groupId>org.eclipse.jetty.aggregate</groupId> <artifactId>jetty-all</artifactId> &
			Lt;version>8.0.4.v20111024</version> </dependency> <!--Jetty Webapp--> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-webapp</artifactId> <version >8.0.4.v20111024</version> </dependency> <!--JSP Support--> <dependency> <groupi D>org.glassfish.web</groupid> <artifactId>javax.servlet.jsp</artifactId> <version> 2.2.3</version> </dependency> <!--EL Support--> <dependency> &LT;GROUPID&GT;ORG.GLASSF Ish.web</groupid> <artifActid>javax.el</artifactid> <version>2.2.3</version> </dependency> <!--JSTL Support --> <dependency> <groupId>org.glassfish.web</groupId> <artifactid>javax.servlet.jsp.js tl</artifactid> <version>1.2.1</version> <exclusions> <exclusion> &LT;ARTIFAC tid>jstl-api</artifactid> <groupId>javax.servlet.jsp.jstl</groupId> </exclusion> &L t;/exclusions> </dependency> </dependencies> </project>
1. Run the standard war file

1.1 First find a complete war package, here using a struts2 with an example application Struts2-blank.war;

1.2 Create your own jetty Server startup class Webappcontextwithwarserver, which specifies the path to the war file and specifies that the context path is "/myapp"

Package com.google.code.garbagecan.jettystudy.sample6;

Import Org.eclipse.jetty.server.Server;
Import Org.eclipse.jetty.webapp.WebAppContext;

public class Webappcontextwithwarserver {public
	static void Main (string[] args) throws Exception {
		Server server = new Server (8080);

		Webappcontext context = new Webappcontext ();
		Context.setcontextpath ("/myapp");
		Context.setwar ("E:/share/test/struts2-blank.war");
		Server.sethandler (context);

		Server.start ();
		Server.join ();
	}
1.3 Run the Webappcontextwithwarserver class and then visit//http://localhost:8080/myapp/to see the struts2 example interface.


2. Run a WebApp directory

2.1 or use the above Struts2-blank.war, the war package after decompression into a directory;

2.2 Create your own jetty Server startup class Webappcontextwithfolderserver, which specifies the WebApp directory and specifies that the context path is "/myapp"

Package com.google.code.garbagecan.jettystudy.sample6;

Import Org.eclipse.jetty.server.Server;
Import Org.eclipse.jetty.webapp.WebAppContext;

public class Webappcontextwithfolderserver {public
	static void Main (string[] args) throws Exception {
		Server ser ver = new Server (8080);

		Webappcontext context = new Webappcontext ();
		Context.setcontextpath ("/myapp");
		Context.setdescriptor ("E:/share/test/struts2-blank/web-inf/web.xml");
		Context.setresourcebase ("E:/share/test/struts2-blank");
		Context.setparentloaderpriority (true);
		Server.sethandler (context);

		Server.start ();
		Server.join ();
	}
2.3 Run the Webappcontextwithfolderserver class and then visit//http://localhost:8080/myapp/to see the struts2 example interface.








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.