Jetty和Tomcat运行Maven Web项目几种方法
来源:互联网 发布:故障报修系统asp源码 编辑:程序博客网 时间:2024/04/28 13:48
目录
1.简介
2.采用Jetty和Tomcat运行Maven Web项目
1.简介
上一篇我们介绍了用Eclipse创建了Maven Web项目,接下来我们介绍怎么运行Maven Web项目方便我们开发和调试,这里使用的是Maven插件的形式引用进来的,这样耦合性比较低,我们需要什么样的工具就引入对应的插件就可以用。
2.采用Jetty和Tomcat运行Maven Web项目
1)采用Jetty运行Maven Web项目
第一步:安装Jetty插件到Eclipse上,首先Eclipse help->install new software 中 Location : http://run-jetty-run.googlecode.com/svn/trunk/updatesite/
把选项勾上,然后等待它 下载安装,完成之后重启 eclipse 即可。
第二步:Maven项目POM.XMl 添加Jetty的插件jetty-maven-plugin,我们要运行test-maven-console项目,所以要在这个项目POM.XML中添加
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${version.jdk}</source> <target>${version.jdk}</target> <showWarnings>true</showWarnings><compilerArguments><verbose /><bootclasspath>${java.home}\lib\rt.jar;${java.home}\lib\jce.jar</bootclasspath></compilerArguments> </configuration> </plugin> <plugin><!-- clean -Djetty.port=9090 jetty:run --> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <configuration> <reload>automatic</reload> <scanIntervalSeconds>10</scanIntervalSeconds> <systemProperties> </systemProperties> <useTestClasspath>true</useTestClasspath> <webAppConfig> <contextPath>/</contextPath> </webAppConfig> </configuration> </plugin><pre name="code" class="java" style="font-size: 18px;"></plugins>说明: maven-compiler-plugin这个插件是编译插件
第三步:配置运行端口等。点击test-maven-console项目右击Run As -->Run Configurations 然后点击Jetty Webapp右击New 配置Jetty版本和Port端口(
不至于端口冲突)
点击RUN运行看后台Console有没有报错,如果没报错就代表运行成功
我们也可以以DUG形式启动,方便我们对项目进行跟踪
2.采用Tomcat运行Maven Web项目
第一步:Eclipse这边不需要引入Tomcat插件,直接在要运行的项目中引入Tomcat插件就可以了,test-maven-console项目添加Tomcat的插件tomcat6-maven-plugin (到2.0版本tomcat-maven-plugin现在已拆分成tomcat7-maven-plugin和tomcat6-maven-plugin了,而groupId也由org.codehaus.mojo改为org.apache.tomcat.maven。)我们这边使用的是tomcat6-maven-plugin
test-maven-console的POM.XML中加入
<!-- tomcat运行 clean tomcat6:run --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> <configuration><!-- http port --> <port>9090</port> <!-- application path always starts with /--> <path>/</path> <uriEncoding>UTF-8</uriEncoding> <systemProperties> <java.io.tmpdir>${project.build.directory}</java.io.tmpdir> </systemProperties> </configuration> </plugin> <plugin><!-- clean cargo:redeploy --> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <configuration> <container> <containerId>tomcat6x</containerId> <type>remote</type> </container> <configuration> <type>runtime</type> </configuration> </configuration> </plugin>
说明:
1.port端口号
2.path以/ 这样在访问时,就不用加入项目名
第三步:配置运行,点击test-maven-console项目Run As-->Run Configurations 然后点击Maven Build右击New 在Goals 输入tomcat6:run 然后点击run运行,查看Console有没有报错。
这时后台没报错,说明能正常运行
Maven 提供的插件很多
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><version>2.6</version></plugin><!-- install插件 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-install-plugin</artifactId><version>2.4</version></plugin><!-- clean插件 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-clean-plugin</artifactId><version>2.5</version></plugin>
比较常用到的插件
总结一下:
运行Maven Web 项目比较常用的是这两种运行,Tomcat运行Maven Web 项目还可以采用另外一种,我们平常比较少用,这里就不具体详细的介绍,
采用的是tomcat:redeploy命令,把Maven Web 项目发布到外部已启动的Tomcat进行测试
在使用Maven 引入JAR 包时,有时会报找不到,这里我在maven使用过程中遇到的问题(依赖jar文件下载失败等)都有介绍,希望能帮助。
- Jetty和Tomcat运行Maven Web项目几种方法
- Jetty和Tomcat运行Maven Web项目几种方法
- Jetty和Tomcat运行Maven Web项目几种方法
- Maven jetty tomcat 运行web项目
- Jetty和Tomcat服务器运行Web项目
- Maven使用Jetty运行Web项目出错
- web项目嵌入Jetty运行的两种方式(Jetty插件和自制Jetty服务器)
- maven 把项目部署到tomcat、jetty插件运行
- maven 发布 web 项目(分别使用 Jetty 和 Tomcat 作为容器)
- Maven + Eclipse + Tomcat - 运行和调试web项目
- Eclipse中创建Maven的Web项目并用jetty运行
- eclipse的maven web项目如何运行(使用jetty)
- eclipse的maven web项目如何运行(使用jetty)
- 使用jetty运行maven项目
- maven 命令创建web项目和jetty插件
- 在eclipse的tomcat下运行webx(maven)工程(区别于jetty下的项目运行)
- tomcat部署web项目的几种方法
- tomcat部署web项目的几种方法
- 基于WiFi的室内定位在美团总部的实践与应用(上)
- eclipse c++ launch failed.Binary not found问题
- 如何配置Java环境
- win7下安装ORACLE 11G 出现:“[INS-32025] 所选安装与指定 Oracle 主目录中已安装的软件冲突” 的问题
- iOS开发笔记之二十——空值(nil值)导致的app崩溃(bug总结一)
- Jetty和Tomcat运行Maven Web项目几种方法
- 余光中:书斋·书灾
- Shell echo用法:shell echo不换行输出、换行输出|shell echo换行符、制表符
- iOS使用keychain和uuid确定设备唯一标识
- [算法系列之七]Manacher算法之最大回文子串
- struts2与hibernate整合出错Unable to instantiate default tuplizer
- 网络营销4p营销策略
- 第九周项目4-乘法口诀表
- 如何解决每次打开office2010都会出现正在配置