在eclipse开发工具中使用jetty启动项目
第一、在eclipse中使用RunJettyRun插件来进行jetty启动
Eclipse中Install New Software 然后Add -> Archive,选择离线包安装即可
或者 将附件离线包直接放到eclipse\plugins文件夹下,重启eclipse就可以使用。
Debug Confingurations >> jetty Webapp 在里面新创建jetty就可以使用
优点:启动比较快
缺点:这种方式获取到的jetty版本比较老
第二、在eclipse>>Install Available Software>>add 添加run-jetty-run 插件,插件地址如下所示:
http://run-jetty-run.googlecode.com/svn/trunk/updatesite
优点:启动比较快 配置方便
缺点:这种方式获取到的jetty版本比较老
第三、在Eclipse和Maven中基于jetty-maven-plugin 插件启动
在pom.xml中添加一下配置
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
<webApp>
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
<contextPath>/</contextPath>
</webApp>
<resourceBases>
<directory>${basedir}/src/main/webapp</directory>
</resourceBases>
</configuration>
</plugin>
在Maven中执行以下命令进行jetty 启动
mvn -Djetty.port=80 jetty:run
注:以上配置简单说明
-Djetty.port=80 : 用以指定jetty启动所占用端口,这里设置的是80
scanIntervalSeconds :设置热部署间隔时间,多长时间自动编译部署一次
allowDuplicateFragmentNames :true 由于Maven 的pom中可能存在一个包多次引用的情况,如果不加这个配置会出现如下错误(jar包冲突错误):
java.lang.IllegalStateException: Duplicate fragment name: spring_web for jar:file:/Users/zhoukai/.m2/repository/org/springframework/spring-web/3.2.2.RELEASE/spring-web-3.2.2.RELEASE.jar!/META-INF/web-fragment.xml and jar:file:/Users/zhoukai/develp/temp/webinf/WEB-INF/lib/spring-web-3.2.2.RELEASE.jar!/META-INF/web-fragment.xml
at org.eclipse.jetty.webapp.MetaData.addFragment(MetaData.java:244)
at org.eclipse.jetty.webapp.FragmentConfiguration.findWebFragments(FragmentConfiguration.java:72)
at org.eclipse.jetty.webapp.FragmentConfiguration.preConfigure(FragmentConfiguration.java:39)
at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:465)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:495)
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:180)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:226)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:164)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:226)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:93)
at org.eclipse.jetty.server.Server.doStart(Server.java:243)
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:67)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
resourceBases:用以指定项目文件所在的路径
contextPath:指定访问的url根目录可以为/hellowWord等等
* jetty的启动端口只能在mvn启动命令中设置
具体jetty-maven-plugin详细配置可参照官网地址: http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin
http://stackoverflow.com/questions/26150681/how-to-hot-redeploy-non-active-maven-project-via-jetty-maven-plugin