jetty作为一个web容器,部署时只需要将部署包扔到 $JETTY_HOME/webapp目录下即可!
例如工程 test.war ,在启动jetty后的访问路径就是 http://localhost:8080/test ,若是我们期望访问 http://localhost:8080/ 即是访问test工程的呢?有两种办法可以解决。
1.直接将 test.war 改名为root.war 。
这个是最简单的做法,也是一般web容器都通用的做法,放到tomcat也是这种做法。
2.修改contexts目录下文件。
这个做法稍微有点麻烦,是通过设置 contexts来达到目的,不期望改变原来的配置文件,所以我们copy配置文件出来。
step1 准备工作
mkdir -p /home/inter12/jetty/webapp/virtual
mkdir -p /home/inter12/jetty/config
mkdir -p /home/inter12/jetty/config/contexts
cp $JETTY_HOME/etc/jetty.xml /home/inter12/jetty/config/
step2 修改配置
vim /home/inter12/jetty/config/jetty.xml
修改其中的
....
<Call name="addLifeCycle">
<Arg>
<New class="org.mortbay.jetty.deployer.ContextDeployer">
<Set name="contexts"><Ref id="Contexts"/></Set>
<!----------------- 将contexts路径设置为我们新的 -------------------->
<Set name="configurationDir">/home/inter12/jetty/config/contexts</Set>
<Set name="scanInterval">5</Set>
</New>
</Arg>
</Call>
.......
<Call name="addLifeCycle">
<Arg>
<New class="org.mortbay.jetty.deployer.WebAppDeployer">
<Set name="contexts"><Ref id="Contexts"/></Set>
<!--------------- 设置webapp 目录 指定到一个虚拟的webapp 。--------------->
<Set name="webAppDir">/home/inter12/jetty/webapp/virtual</Set>
<Set name="parentLoaderPriority">false</Set>
<Set name="extract">true</Set>
<Set name="allowDuplicates">false</Set>
<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
</New>
</Arg>
</Call>
......
cd /home/inter12/jetty/config/contexts
新建一个 test.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 class="org.mortbay.jetty.webapp.WebAppContext">
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Required minimal context configuration : -->
<!-- + contextPath -->
<!-- + war OR resourceBase -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="contextPath">/</Set>
<!-- 这里必须加上war这个结尾 - - - - - - - - - - - - - - - - - - - - -->
<Set name="war">/home/inter12/jetty/webapp/test.war</Set>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Optional context configuration -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="extractWAR">true</Set>
<Set name="copyWebDir">false</Set>
</Configure>
好了,到这里就已经基本结束了。
启动jetty
cd $JETTY_HOME
java -jar start.jar /home/inter12/jetty/config/jetty.xml
那么访问 http://localhost:8080/test 等同于 http://localhost:8080
TIPS:
若是通过contexts来配置 / 访问的话,那么war就不要放在webapp目录下,jetty会加载两边,若是配置了log4j的话,就会出现一下错误,切记!!!
Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
分享到:
相关推荐
jetty-web.xml–Web App configuration jetty-env.xml–JNDI configuration webdefault.xml–Pre-web.xml configuration override-web.xml–Post-web.xml configuration 特性参考 SSL Connectors参考 QoSFilter参考 ...
将改文件复制到jetty的路径下,可以启动jetty路径去测试
Jetty配置支持HTTPS以及受信网站证书生成方式
jetty-security-9.4.8.v20171121.jar,jetty-io-9.4.8.v20171121.jar,jetty-continuation-9.4.8.v20171121.jar,jetty-client-9.4.8.v20171121.jar,jetty-jmx-9.4.8.v20171121.jar,jetty-plus-9.4.8.v20171121....
自己写的jetty6在eclipse启动中配置说明
Jetty嵌入项目代码中示例,现我有一示例项目 e:/workspace/web-demo(称为project_home),里面的Web根目录是WebContent。 在project_home建一个jetty目录,子目录如:contexts、etc、lib。 把${jetty_home}/etc...
赠送jar包:jetty-io-9.4.43.v20210629.jar; 赠送原API文档:jetty-io-9.4.43.v20210629-javadoc.jar; 赠送源代码:jetty-io-9.4.43.v...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
eclipse jetty插件,从...下载run-jetty-run.zip文件,解压后再编写个links文件丢到eclipse的dropins目录下即可,省去了使用eclipse update方式安装的麻烦。 link文件样例如: path=d:\\eclipse_plugins\\run-jetty-run
Jetty中文手册打包下载
Jetty软件包内容: jetty-distribution-9.4.51.v20230217.tar.gz jetty-distribution-9.4.51.v20230217.zip jetty-home-10.0.15.tar.gz jetty-home-10.0.15.zip jetty-home-11.0.15.tar.gz jetty-home-11.0.15.zip ...
jetty是什么 jetty配置 jetty使用 jetty嵌入 jetty启动 jetty部署 jetty教程 jetty嵌入式 jetty
赠送jar包:jetty-server-9.4.8.v20171121.jar; 赠送原API文档:jetty-server-9.4.8.v20171121-javadoc.jar; 赠送源代码:jetty-server...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
.jetty
jetty嵌入式服务器开发所必须的jar包,本人使用jetty版本为6.1.3,jar包总数为9个,来自jetty:commons-el-1.0.jar,jasper-compiler-5.5.15,jasper-compiler-jdt-5.5.15.jar,jasper-runtime-5.5.15.jar,jetty-...
jetty-9.4.6
jetty相关所有jar包,包含jar包: jetty-continuation-8.1.15.v20140411,jetty-http-8.1.15.v20140411,jetty-io-8.1.15.v20140411,jetty-security-8.1.15.v20140411,jetty-server-8.1.15.v20140411,jetty-util-8.1.15...
jetty 学习资料合集 jetty 学习资料合集 jetty 学习资料合集 jetty 学习资料合集
这是一个jetty容器、和tomcat是一个级别的,但是这个启动是非常快的,一般都是用于开发。
maven集成jetty必须jar包maven-jetty-plugin,内含多个版本
Jetty 7是Jetty奔向Eclipse后发布的第一个版本,本次的Jetty 7 RC2带给了我们一个十分诱人的新特性-支持跨域名Ajax请求。众所周知因为安全的原因,多数浏览器都限制了Ajax跨域请求和javascript加载的时候只能是与...