日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Jetty实战之 嵌入式Jetty运行web app

發布時間:2025/5/22 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Jetty实战之 嵌入式Jetty运行web app 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Jetty實戰之 嵌入式Jetty運行web app

博客分類:
  • ?
  • 應用服務器
jettywar?

轉載地址:http://blog.csdn.net/kongxx/article/details/7237034

要說嵌入式運行Jetty,最常用的還應該是運行一個標準的war文件或者指定一個webapp目錄。

0. 首先需要添加Jetty運行時webapp的依賴包,下面是一個完整的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.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. 運行標準的war文件

1.1 首先找一個完整的war包,這里使用了struts2自帶的一個例子應用程序struts2-blank.war;

1.2 創建自己的Jetty Server啟動類WebAppContextWithWarServer,其中指定了war文件的路徑,并指定context路徑為"/myapp"

Java代碼??
  • 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 運行WebAppContextWithWarServer類,然后訪問// http://localhost:8080/myapp/就可以看到struts2的例子界面了。

    ?

    2. 運行一個webapp目錄

    2.1 還是用上面的struts2-blank.war,將這個war包解壓后放到一個目錄下;

    2.2 創建自己的Jetty Server啟動類WebAppContextWithFolderServer,其中指定了webapp目錄,并指定context路徑為"/myapp"

    Java代碼??
  • 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?server?=?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 運行WebAppContextWithFolderServer類,然后訪問// http://localhost:8080/myapp/就可以看到struts2的例子界面了。

    轉載于:https://www.cnblogs.com/yangmengdx3/p/4744543.html

    總結

    以上是生活随笔為你收集整理的Jetty实战之 嵌入式Jetty运行web app的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。