




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、MavenWeb 项目部署到 Tomcat本文标签:MavenJava通过 Maven 来搭建项目是越来越多人的选择,我也就凑了一下热闹,用 maven 来搭建了项目,发现还挺好用,但是也遇到了很多问题,下面记录一下 Web 项目部署到 Tomcat 下的问题。1、普通的 WE 欧目,就是虽然是用 maven 搭建的,但是没有使用 profiles.xml 文件来配置参数。这样的项目可以通过以下的方式进行部署:直接 mvncleanpackage-DskipTests,进行打包,1)然后在可以把 war 包拷到 tomcat 目录下的 Webapp 目录下2)修改 tomcat 目录下的 co
2、nf 目录下的 server.xml 文件,在 Host 标签之间添加如下一句话:ContextdocBase=D:IdeaProjectsTestexampleexample-webtargetexample-webreloadable=falsepath=/2、使用 profiles.xml 配置了默认参数,而在 web 的配置文件中使用到了这些参数,这个时候使用命令打包的时候要指定你要使用哪一个 profilesid 来装配你的项目,命令如下mvncleanpackage-Pdevelopment,其中-p 是指启用哪个 profilesid。然后下面部署到 tomcat 的方法和上面的
3、就一样了使用 maven 的话推荐一个 IDE 工具 IntellijIDEA,他可以直接通过视图话的方式进行指定 profilesid。下面转一篇文章,讲 profile 的Profiles 是 maven 的一个很关键的术语:profile 是用来定义一些在 buildlifecycle中使用的 environmentalvariations,profile 可以设置成在不同的环境下激活不同的profile(例如:不同的 OS 激活不同的 profile,不同的 JVM 激活不同的 profile,不同的dabase 激活不同的 profile 等等)。定义 Profiles你可以把 pr
4、ofiles 定义在 4 个地方:1、%M2_HOME%/conf/settings.xml,这是针对该部电脑的所有 user 的 profiles,是globalprofiles,它会影响所有的 mavenprojectbuild2、 /.m2/settings.xml,这是针对 peruser 的 profiles,是 user 级的 profiles,它会影响当前 user 的所有mavenprojectbuild3、定义在 pom.xml 文件里面,这是仅针对该 project 的 profiles,是 project 级的profiles4、profiles.xml,它和 pom.x
5、ml 在同个目录下,也是 project 级白 pprofiles,使用profiles.xml 的目的是希望把 profiles 的设置从 pom.xml 里抽离出来设置。定义在这 4 个地方的 profiles 中,涉及范围越窄的 profiles 会覆盖范围越宽的profiles。即:定义在 pom.xml 里 profiles 会覆盖 profiles.xml 的,profiles.xml 的会覆盖/.m2/settings.xml的,/.m2/settings.xml 的会覆盖M2_HOME%/conf/settings.xml 的。不过请注意:设置在 pom.xml 里的 prof
6、iles 是最最推荐的,因为 pom.xml 会被 deploy至 Urepository 里,所以 pom.xml 里的 profiles 才会 availableforsubsequentbuildsoriginatingfromtherepositoryorastransitivedependencies。而 settings.xml和 profiles.xml 里定义的 profiles 不会被 deploy 至 Urepository,则有诸多限制,因此,只有下面几个 profiles 能够在 settings.xml 和 profiles.xml 里定义:repositoriesp
7、luginRepositoriesproperties其他类型的 profiles 必须在 pom.xml 里定义(上面 3 个 profiles 也可以在 pom.xml 里定义)。Pom.xml 能够定义的 profiles 包括:(notactuallyavailableinthemainPOM,butusedbehindthescenes)asubsetoftheelement,whichconsistsof:2、激活 Profiles激活 profiles 有下列几种方式:ExplicitlyThroughMavensettingsBasedonenvironmentvariable
8、sOSsettingsPresentormissingfiles1)通过 mvn 命令的-P 参数来显示激活 profiles,该参数值是 profileidlist(之间用逗号连接)。如:mvngroupId:artifactId:goal-PprofileId-1,profileId-22)通过在 settings.xml 里设置 element 来激活(当然也必须在 settings.xml 里定义)fileprofilesprofile-1activeProfileactiveProfiles.settings列在里的 profilesli
9、st 会在每一个 project 执行时被激活3)Profiles 还可以基于 detect 至 U 的 buildenvironment 的 state 来自动激活,而不需要象上面 2 种方式显式激活。这只需要在 profile 定义时使用 element。如:1.4fileprofiles上面的代码表示:如果 JDKversionstartwith1.4(eg.1.4.0_08,1.4.2_07,1.4),该 profile 会被激活fileprofiles上面的代码表示:如果存在 system
10、propertiedebug”,该 profile 会被激活。为了激活它,输入的命令类似于:mvngroupId:artifactId:goal-Dfileprofiles上面的代码表示:如果存在 systempropertieaenvironment的值为 test,该 profile会被激活。为了激活它,输入的命令类似于:mvngroupId:artifactId:goal-Denvironment=test4)Profiles 还可以基于 OSsetting 来自动激活WindowsXP
11、nameWfileprofiles上面的代码表示:如果 OS 为 windowsxp,该 profile 会被激活5)根据某个 file 不存在而激活 profile。例如下面定义的 profile 是在target/generated-sources/axistools/wsdl2java/org/apache/maven 不存在时激活target/generated-sources/axistools/wsdl2java/org/apache/mavenmissingfileactivati
12、fileprofiles使用 Profiles 时要注意的 2 个问题第一、externalproperties不是定义在 pom.xml 里的 properties 者 B 称为 externalproperties。举例说明最明了:pom.xml:.org.myco.pluginsgroupIdspiffy-integrationTest-pluginartifactId1.0version$appserver.homeappserverHject/.m2/settings.xml.appserver
13、Configid/path/to/appserverappserver.homepropertiesprofileprofilesappserverConfigactiveProfileactiveProfiles.settings当你执行该 pom 时,运行正常。但如果 anotheruser 执行时,则运行失败,因为无法解析$appserver.home(这是由于该 properties 是定义在 user 级另1J 的 settings.xml)。解决方法就是把该 profile 放到 pom.xml 里定义,但这样做的缺点是所有使用该profile 的 pom.xml 每个都要定义一次
14、该 profile。最好的解决方法是:SinceMavenprovidesgoodsupportforprojectinheritance,itspossibletostickthissortofconfigurationinthepluginManagementsectionofateam-levelPOMorsimilar,andsimplyinheritthepaths第二、pom.xml 里定义的 profiles 不符合激活条件依然是举个例子:pom.xml:.appserverConfig-devidenvnamedevvaluepropertyactivation/path/to
15、/dev/appserverappserver.homepropertiesprofileappserverConfig-dev-2idenvnamedev-2valuepropertyactivation/path/to/dev/appserver2appserver.homepropertiesprofileprofilesorg.myco.pluginsgroupIdspiffy-integrationTest-pluginartifactId1.0version$appserver.homeappserverHomeconfigurationplugin.pluginsbuild.pr
16、oject上面定义的 pom.xml 定义了两个 profile:不同的env参数值会激活不同的 profile当执行命令:mvn-Denv=dev-2integration-test就会激活 profile“appserverCon 巾 g-dev-2”当执行命令:mvn-Denv=devintegration-test就会激活 profile“appserverCon 巾 g-dev”而当执行命令:mvn-Denv=productionintegration-test则运行失败,因为没有激活任何一个 profile,因此无法解析$appserver.home查看 buildtime 过程中使用了哪些 Profiles执行 helpplugin 的 active-profilesgoal,使用命令:mvnhelp:active-profiles例子:对于上面的例子,如果输入命令:mvnhelp:active-profiles-Denv=dev则输出的是:Thefollowingprofilesareactive:-appserverConfig-dev(source:pom)如果有一个 profile 定义在 settings.xml 里并
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025短租租赁合同:教育培训场地租赁协议
- 2025年典当合同范本:汽车典当贷款操作细则
- 2025年轨道交通信号电缆项目采购合同
- 2025店长聘用协议:商业地产店长岗位竞聘标准
- 2025年度水利工程水泵安装与防冻合同
- 2025年康复医疗服务体系优化与运营模式创新策略研究报告
- 2025年度图书馆图书采购与读者服务合同
- 2025版企业办公设备维修与保养服务合同
- 2025年新能源汽车专用停车位买卖合同
- 2025版闲置土地居间服务合同
- T/CIE 168-2023企业级固态硬盘测试规范第4部分:兼容性测试
- 小区施工押金协议书
- 企业法律合规培训课件
- (2025)义务教育英语课程标准(2025年版)测试题含答案
- 多高层木结构建筑技术标准
- (高清版)DB33∕T 386-2013 内河航道工程质量检验规范
- 蒸汽管道试压作业方案
- 《餐饮食堂厨房消防安全》知识培训
- 质量控制在银行业中的应用
- 热射病的护理诊断和措施
- 三年级科学教材培训心得
评论
0/150
提交评论