Jetty Embedded Jetty running web App

Source: Internet
Author: User
Tags glassfish

Jetty Embedded Jetty running web App Blog Category:
    • Application Server
Jettywar

Reprint Address: http://blog.csdn.net/kongxx/article/details/7237034

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

0. First you need to add a dependency package for the Jetty Runtime WebApp, here is a complete pom.xml file

Wrote <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>
<target>1.6</target>
<debug>true</debug>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!--Spring Support--
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>

<!--Jetty--
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all</artifactId>
<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>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp</artifactId>
<version>2.2.3</version>
</dependency>

<!--EL Support--
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>2.2.3</version>
</dependency>

<!--JSTL Support--
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.1</version>
<exclusions>
<exclusion>
<artifactId>jstl-api</artifactId>
<groupId>javax.servlet.jsp.jstl</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

1. Running a standard war file

1.1 First find a complete war package, here use a struts2 to bring 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"

Java code
  1. Package com.google.code.garbagecan.jettystudy.sample6;
  2. Import Org.eclipse.jetty.server.Server;
  3. Import Org.eclipse.jetty.webapp.WebAppContext;
  4. Public class Webappcontextwithwarserver {
  5. public static void Main (string[] args) throws Exception {
  6. Server server = new server (8080);
  7. Webappcontext context = new Webappcontext ();
  8. Context.setcontextpath ("/myapp");
  9. Context.setwar ("E:/share/test/struts2-blank.war");
  10. Server.sethandler (context);
  11. Server.start ();
  12. Server.join ();
  13. }
  14. }

1.3 Run the Webappcontextwithwarserver class and then access//http://localhost:8080/myapp/to see the example interface of STRUTS2.

2. Run a WebApp directory

2.1 or use the above Struts2-blank.war, the war package decompression and put 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"

Java code
  1. Package com.google.code.garbagecan.jettystudy.sample6;
  2. Import Org.eclipse.jetty.server.Server;
  3. Import Org.eclipse.jetty.webapp.WebAppContext;
  4. Public class Webappcontextwithfolderserver {
  5. public static void Main (string[] args) throws Exception {
  6. Server server = new server (8080);
  7. Webappcontext context = new Webappcontext ();
  8. Context.setcontextpath ("/myapp");
  9. Context.setdescriptor ("E:/share/test/struts2-blank/web-inf/web.xml");
  10. Context.setresourcebase ("E:/share/test/struts2-blank");
  11. Context.setparentloaderpriority (true);
  12. Server.sethandler (context);
  13. Server.start ();
  14. Server.join ();
  15. }
  16. }

2.3 Run the Webappcontextwithfolderserver class and then access//http://localhost:8080/myapp/to see the example interface of STRUTS2.

Jetty Embedded Jetty running web App

Related Article

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.