最近开始选择JETTY作为服务器了,乘这现在空闲点学习了些JETTY的部署知识,原来她真的跟TOMCAT很类似,先总结如下:

部署应用方法(下载好jetty);

方法一:

直接将应用的 war包放在jetty_home/webapps下,启动jetty(命令:java -jar start.jar),默认jetty的端口是8080,在IE输入http://localhost:8080/jetty/jsp/login.jsp 即可。

方法二(动态部署):

1.拷贝jetty_home/contexts/test.xml到相同目录,更改名称为jetty.xml,修改改xml内容如下(红色标识部分):

<?xml version="1.0"  encoding="ISO-8859-1"?>

<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">

<!-- ==================================================================

Configure and deploy the test web application in $(jetty.home)/webapps/test

Note. If this file did not exist or used a context path other that /test

then the default configuration of jetty.xml would discover the test

webapplication with a WebAppDeployer.  By specifying a context in this

directory, additional configuration may be specified and hot deployments

detected.

===================================================================== -->

<Configure class="org.mortbay.jetty.webapp.WebAppContext">

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<!-- Required minimal context configuration :                        -->

<!--  + contextPath                                                  -->

<!--  + war OR resourceBase                                          -->

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<Set name="contextPath">/jetty</Set>

<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/jetty</Set>

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<!-- Optional context configuration                                  -->

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<Set name="extractWAR">false</Set>

<Set name="copyWebDir">false</Set>

<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>

<!--  <Set name="overrideDescriptor"><SystemProperty name="jetty.home" default="."/>/contexts/test.d/override-web.xml</Set>-->

<!-- virtual hosts

<Set name="virtualHosts">

<Array type="String">

<Item>www.myVirtualDomain.com</Item>

<Item>localhost</Item>

<Item>127.0.0.1</Item>

</Array>

</Set>

-->

<!-- disable cookies

<Get name="sessionHandler">

<Get name="sessionManager">

<Set name="usingCookies" type="boolean">false</Set>

</Get>

</Get>

-->

<Get name="securityHandler">

<Set name="userRealm">

<New class="org.mortbay.jetty.security.HashUserRealm">

<Set name="name">Test Realm</Set>

<Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>

<!-- To enable reload of realm when properties change, uncomment the following lines -->

<!-- changing refreshInterval (in seconds) as desired                                -->

<!--

<Set name="refreshInterval">5</Set>

<Call name="start"></Call>

-->

</New>

</Set>

<Set name="checkWelcomeFiles">true</Set>

</Get>

<!-- Non standard error page mapping -->

<!--

<Get name="errorHandler">

<Call name="addErrorPage">

<Arg type="int">500</Arg>

<Arg type="int">599</Arg>

<Arg type="String">/dump/errorCodeRangeMapping</Arg>

</Call>

</Get>

-->

</Configure>

2.将应用的war文件解压到jetty_home/webapps下(与配置文件jetty.xml中的<Set name="war">设置的路径匹配)


 之后启动jetty即可完成部署。

方法三(使用jetty插件,适用于单个工程的应用,且个文件放在maven默认路径):
在应用的pom.xml文件中添加jetty插件配置如下;
<build>
       <!-- jetty插件 -->
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.10</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <stopKey>foo</stopKey>
                    <stopPort>9999</stopPort>
                </configuration>
                <executions>
                    <execution>
                        <id>start-jetty</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <scanIntervalSeconds>0</scanIntervalSeconds>
                            <daemon>true</daemon>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-jetty</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
运行命令:mvn jetty:run 即可启动jetty服务,默认端口是8080,在IE输入http://localhost:8080/jetty/jsp/login.jsp 即可。
停止服务可直接ctrl+c或者运行mvn jetty:stop即可。
开启服务后可以实现热部署功能,修改jsp或java代码均可。
 
或配置如下:
<plugin> 
<groupId>org.mortbay.jetty</groupId> 
<artifactId>maven-jetty-plugin</artifactId> 
<version>6.1.22</version> 
<configuration> 
<contextPath>/</contextPath> 
<connectors> 
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> 
<port>8081</port> 
<maxIdleTime>60000</maxIdleTime> 
</connector> 
</connectors> 
<requestLog implementation="org.mortbay.jetty.NCSARequestLog"> 
<filename>target/access.log</filename> 
<retainDays>90</retainDays> 
<append>false</append> 
<extended>false</extended> 
<logTimeZone>GMT+8:00</logTimeZone> 
</requestLog> 
<systemProperties> 
<systemProperty> 
<name>productionMode</name> 
<value>false</value> 
</systemProperty> 
</systemProperties> 
</configuration> 
</plugin> 
指定jetty端口为8081,且直接输入http://localhost:8081/jsp/login.jsp 即可
 
 
jetty知识:
如果启动脚本不在jetty目录下,则需执行如下命令启动jetty;
D:\>"D:/Program Files/Java/jdk1.6.0_20\bin\java" -jar d:/jetty-distribution-7.4.
2.v20110526/start.jar --ini=d:/jetty-distribution-7.4.2.v20110526/start.ini -Dje
tty.home=d:/jetty-distribution-7.4.2.v20110526
 
如果启动脚本在jetty目录下则只需:java -jar start.jar
 
-------------------------------------------------------------------------------------
利用macen的jetty插件调试工程:
在pom中添加jetty插件:
<build>
 
     <plugins>
<plugin>
       <groupId>org.mortbay.jetty</groupId>
       <artifactId>maven-jetty-plugin</artifactId>
       <version>6.1.9</version>
       <configuration>
    <contextPath>/</contextPath>
     <scanIntervalSeconds>3</scanIntervalSeconds>
     <scanTargetPatterns>
<scanTargetPattern>
       <directory>src/main/webapp</directory>
</scanTargetPattern>
      </scanTargetPatterns>
      </configuration>
              </plugin>
     </plugins>
  </build>
1、先来配置一个外部工具,来运行JETTY:
选择菜单Run->External Tools->External Tools Configurations ...在左边选择Program,再点New:
配置Location为mvn完整命令行。定位到bin下的mvn.bat
选择Working Directory为本项目。
Arguments填写:jetty:run

 
再点选Enviroment页:加入MAVEN_OPTS变量,值为:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8088,server=y,suspend=y
其中,如果suspend=n 表示不调试,直接运行。address=8080为端口
然后,点APPLY,再点run已启动jetty.

 
另外注意一点,好像external tool菜单项在java browering的perspective下才会出现。如果在java下看不见,可以切换下试试。
2、调试应用
右键点击工程,选debug as ->debug configurations...

 
选中左树中的Remote Java Application,再点New。
选择你的项目,关键是要填和之前设置外部工具时相同的端口号。

 点击apply,再点击degug即可。

Jetty实战(杂七杂八)的更多相关文章

  1. Jetty实战之 嵌入式Jetty运行Servlet

    http://blog.csdn.net/kongxx/article/details/7230080 Jetty实战之 嵌入式Jetty运行Servlet 分类:JettyJava (19530)  ...

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

    Jetty实战之 嵌入式Jetty运行web app 博客分类: 应用服务器 jettywar  转载地址:http://blog.csdn.net/kongxx/article/details/72 ...

  3. Jetty实战之 安装 运行 部署

    本文地址:http://blog.csdn.net/kongxx/article/details/7218767 1. 首先从Jetty的官方网站http://wiki.eclipse.org/Jet ...

  4. (转)Jetty实战之 安装 运行 部署

    http://blog.csdn.net/kongxx/article/details/7218767 本文地址:http://blog.csdn.NET/kongxx/article/details ...

  5. 第02篇. Jetty 9 实战之安装/运行/部署

    一直以来,想改变一些自己早已经习惯的事情. 一直都听说jetty跟Tomcat一样,是一个web容器. 一直都是在说等等,再等等,等有时间的时候! 一直都是给自己一些逃避的理由 1. 首先从Jetty ...

  6. Jetty直接调试,不用部署,不用弄一些杂七杂八的设置

    以前调试web程序的,搭建Tomcat实在是费劲,就想找一个比较简单的方式,我就想调试一下我写的某一个servlet形式,看到<how Tomcat works>这本书,才明白确实可以,不 ...

  7. Spark入门实战系列--2.Spark编译与部署(中)--Hadoop编译安装

    [注]该系列文章以及使用到安装包/测试数据 可以在<倾情大奉送--Spark入门实战系列>获取 .编译Hadooop 1.1 搭建环境 1.1.1 安装并设置maven 1. 下载mave ...

  8. Spark入门实战系列--6.SparkSQL(下)--Spark实战应用

    [注]该系列文章以及使用到安装包/测试数据 可以在<倾情大奉送--Spark入门实战系列>获取 .运行环境说明 1.1 硬软件环境 线程,主频2.2G,10G内存 l  虚拟软件:VMwa ...

  9. Spark入门实战系列--7.Spark Streaming(下)--实时流计算Spark Streaming实战

    [注]该系列文章以及使用到安装包/测试数据 可以在<倾情大奉送--Spark入门实战系列>获取 .实例演示 1.1 流数据模拟器 1.1.1 流数据说明 在实例演示中模拟实际情况,需要源源 ...

随机推荐

  1. RabbitMQ(3) Java客户端使用

    RabbitMQ针对不同的开发语言(java,python,c/++,Go等等),提供了丰富对客户端,方便使用.就Java而言,可供使用的客户端有RabbitMQ Java client. Rabbi ...

  2. Ubuntu 13.10 如何修改背景色--豆沙绿

    如何修改Ubunut 13.10的窗口背景色,在网上找到了多资料,安装了dconf,Unity Tweak Tool,GNOME Color Chooser都无法修改背景色. 最后,还是直接去修改主题 ...

  3. python命名空间的本质

    Python的命名空间是Python程序猿必须了解的内容,对Python命名空间的学习,将使我们在本质上掌握一些Python中的琐碎的规则. 接下来我将分四部分揭示Python命名空间的本质:一.命名 ...

  4. qml 源码样例

    https://github.com/CodeBees/qtExample https://github.com/zhengtianzuo/QtQuickExamples/blob/master/RE ...

  5. webpack 事件触发 按需加载

    比较易懂, 方法简单 var util_sync = require('./util-sync.js') alert(util_sync.data) document.getElementById(& ...

  6. 微信小程序页面跳转方法汇总

    微信小程序前端页面跳转有多种方式,汇总如下: Tips: 小程序前端的页面跳转之后,跳转之前的页面并不会凭空消失,而是存进了一个类似“页面栈”的空间里: 只有当这个所谓的“页面栈”满了之后页面才会退出 ...

  7. StringUtils.isEmpty和StringUtils.isBlank的区别

    两个方法都是判断字符是否为空的.前者是要求没有任何字符,即str==null 或 str.length()==0:后者要求是空白字符,即无意义字符.其实isBlank判断的空字符是包括了isEmpty ...

  8. 使用Sinopia搭建私有npm仓库

    使用Sinopia搭建私有npm仓库 在用npm装包的时候,每次都要下载一大堆,慢且不说,npm还老被墙,所以就想到在公司内部搭建npm仓库镜像.大概看了几个,觉得Sinopia最简单也好用,所以就使 ...

  9. JMter压力测试

    一. 压力测试场景设置 一般我们在做压力测试的时候,分单场景和混合场景,单场景也就是咱们压测单个接口的时候,多场景也就是有业务流程的情况下,比如说一个购物流程,那么这样的场景就是混合场景,就是有多个接 ...

  10. No form of payment has been added yet.

    You may select a form of payment after your account balance reaches $10.00. Learn more 显然是说达到10美元以后才 ...