Jetty和Tomcat运行Maven Web项目几种方法
来源:互联网 发布:三菱plc编程入门 pdf 编辑:程序博客网 时间:2024/04/29 01:33
目录
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>
第三步:配置运行端口等。点击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项目的几种方法
- Java 基础之-枚举
- Lintcode 最小差
- 私有属性的private的setter和getter方法来获取一个人的属相以及生存的天数
- 正则表达式
- nexus 搭建maven本地仓库
- Jetty和Tomcat运行Maven Web项目几种方法
- 比特币(BitCoin)学习第一天-比特币(BitCoin)的价值?7年涨了300万倍!
- Oracle中的INSTR,NVL和SUBSTR函数的用法代码实例
- php變量
- Android (向服务器提交数据)
- Java List 和 数组之间的相互转化
- test
- hdu5251 凸包 旋转卡壳
- Java中浅拷贝与深拷贝的区别