java 集成jetty_jetty与maven集成

自己做个小项目,使用了

maven2

,一直使用

tomcat

,但很不方便。采用直接改

server.xml

指向项目路径的方法,但这样要求把编译路径改向

WEB-INF/classes

,而且要求把需要的

jar

放到

WEB-INF/lib

下去。而如果修改了

pom

文件,就需要重新

mvn eclipse:eclipse

,修改项目文件,然后编译路径又会变成

target/classes

,然后还需要把

jar

拷到

lib

下去,很是麻烦。尝试使用

resin

,也是采用

maven

的方式,但官方

maven

repository

上只有一个版本,然后需要

jca1.5

,结果上面又没有,自己作弊吧,终归不爽。正好

alin

建议用

jetty

,就按他的文档尝试了一下。

Pom

文件中加上以下依赖,然后

mvn eclipse:eclipse

,会到官方的

repo

down

这些

jar

,其中

ant

因为较大(

1M

)可能会失败,可以重试解决。如果这些

jar

的同一版本以前

maven

下过就不会重复下,这也体现了

maven

的一些优势。

<

dependency

>

<

groupId

>

tomcat

groupId

>

<

artifactId

>

jasper-compiler

artifactId

>

<

version

>

5.5.15

version

>

<

scope

>

test

scope

>

dependency

>

<

dependency

>

<

groupId

>

tomcat

groupId

>

<

artifactId

>

jasper-runtime

artifactId

>

<

version

>

5.5.15

version

>

<

scope

>

test

scope

>

dependency

>

<

dependency

>

<

groupId

>

commons-el

groupId

>

<

artifactId

>

commons-el

artifactId

>

<

version

>

1.0

version

>

<

scope

>

test

scope

>

dependency

>

<

dependency

>

<

groupId

>

org.mortbay.jetty

groupId

>

<

artifactId

>

org.mortbay.jetty

artifactId

>

<

version

>

5.1.10

version

>

<

scope

>

test

scope

>

dependency

>

<

dependency

>

<

groupId

>

javax.servlet

groupId

>

<

artifactId

>

jsp-api

artifactId

>

<

version

>

2.0

version

>

<

scope

>

test

scope

>

dependency

>

<

dependency

>

<

groupId

>

ant

groupId

>

<

artifactId

>

ant

artifactId

>

<

version

>

1.6.5

version

>

<

scope

>

test

scope

>

dependency

>

然后放写一个

RunJetty.Java

,同包放一个

jetty-config.xml

(建议放

test

相关包里)。在

eclipse

里运行

RunJetty

,就启动

jetty

了,它会使用当前项目的

class loader

,所以不用更改编译路径,也不用拷贝

jar

了。

jetty-config

的配置很简单,大家一看就知道了。具体文件如下:

import java.net.URL;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import org.mortbay.jetty.Server;

public class RunJetty {

private static Log log = LogFactory.getLog(RunJetty.class);

/**

* @param args

*/

public static void main(String[] args) {

Server jettyServer = null;

try {

URL jettyConfig = RunJetty.class.getResource("jetty-config.xml");

if (jettyConfig == null) {

log

.fatal("Unable to locate jetty-test-config.xml on the classpath");

}

jettyServer = new Server(jettyConfig);

jettyServer.start();

} catch (Exception e) {

log.fatal("Could not start the Jetty server: " + e);

if (jettyServer != null) {

try {

jettyServer.stop();

} catch (InterruptedException e1) {

log.fatal("Unable to stop the jetty server: " + e1);

}

}

}

}

}

----------------------------------------------

xml

version

=

"1.0"

?>

DOCTYPE

Configure

PUBLIC

"-//MortBay Consulting//DTD Configure 1.2//EN"

"http://jetty.mortbay.org/configure_1_2.dtd"

>

<

Configure

class

=

"org.mortbay.jetty.Server"

>

<

Call

name

=

"addListener"

>

<

Arg

>

<

New

class

=

"org.mortbay.http.SocketListener"

>

<

Set

name

=

"Port"

type

=

"int"

>

<

SystemProperty

name

=

"jetty.port"

default

=

"80"

/>

Set

>

New

>

Arg

>

Call

>

<

Call

name

=

"addWebApplication"

>

<

Arg

>

/

Arg

>

<

Arg

>

web

Arg

>

Call

>

<

Set

name

=

"requestsPerGC"

type

=

"int"

>

2000

Set

>

<

Set

name

=

"statsOn"

type

=

"boolean"

>

false

Set

>

Configure

>

posted on 2006-05-15 11:19 pesome 阅读(1970) 评论(0)  编辑  收藏 所属分类: 开源软件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值