via: http://www.blogjava.net/baoyaer/articles/193523.html
关于tomcat5.5有几个地方需要说一下:
1.tomcat5.5以后的版本都没有集成admin(管理端),需要独立下载,下载后解压到apache-tomcat-5.5.17\server\webapps\admin目录下
2.如果现在启动tomcat服务是无法登录localhost:8080/admin和localhost:8080/manager的,需要配置apache-tomcat-5.5.17conf\tomcat-users.xml文件,内容如下:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="admin"/>
<role rolename="manager"/><!-- 保留此项配置,方便进入页面管理项目 -->
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="admin" password="admin" roles="admin"/>
<user username="manager" password="manager" roles="manager,manager-gui,manager-script"/>
</tomcat-users>
注意:admin用户和manager用户不能是同一个,否则同时访问localhost:8080/admin和localhost:8080/manager时会有问题
3.tomcat的admin和manager配好后,启动服务。
4.用maven2新建一个web项目,然后配置pom.xml文件
4.1配置tomcat的manager
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager</url> <!-- tomcat7下此处为 http://localhost:8080/manager/text -->
<server>myserver</server>
</configuration>
</plugin>
</plugins>
</build>
在settings.xml中,找到servers标签,加入如下代码:
<server>
<id>myserver</id>
<username>manager</username> <!-- tomcat的manager用户名,见上面的tomcat-users.xml文件 -->
<password>manager</password> <!-- tomcat的manager用户登录的密码 -->
</server>
以上也可以合在一起
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager</url> <!-- tomcat7下此处为 http://localhost:8080/manager/text -->
<username>manager</username>
<password>manager</password>
<path>/mycontext</path>
</configuration>
</plugin>
</plugins>
</build>
4.2设置web项目的war包名(maven2打包和发布到tomcat目录下的war包名)
<build>
<finalName>mycontext</finalName>
</build>
4.3可以将war包映射到tomcat的不同context
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<path>/mycontext</path>
</configuration>
</plugin>
5.用maven2发布war包
部署:mvn tomcat:deploy
撤销部署:mvn tomcat:undeploy
启动web应用:mvn tomcat:start
停止web应用:mvn tomcat:stop
重新部署:mvn tomcat:redeploy
部署展开的war文件:mvn war:exploded tomcat:exploded
更多的项目信息
name:项目除了artifactId外,可以定义多个名称
description: 项目描述
url: 项目url
inceptionYear:创始年份
Licenses
<licenses>
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses>
Organization
配置组织信息
<organization>
<name>Codehaus Mojo</name>
<url>http://mojo.codehaus.org</url>
</organization>
Developers
配置开发者信息
<developers>
<developer>
<id>eric</id>
<name>Eric</name>
<email>[email protected]</email>
<url>http://eric.propellors.net</url>
<organization>Codehaus</organization>
<organizationUrl>http://mojo.codehaus.org</organizationUrl>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
<timezone>-6</timezone>
<properties>
<picUrl>http://tinyurl.com/prv4t</picUrl>
</properties>
</developer>
</developers>
Contributors
<contributors>
<contributor>
<name>Noelle</name>
<email>[email protected]</email>
<url>http://noellemarie.com</url>
<organization>Noelle Marie</organization>
<organizationUrl>http://noellemarie.com</organizationUrl>
<roles>
<role>tester</role>
</roles>
<timezone>-5</timezone>
<properties>
<gtalk>[email protected]</gtalk>
</properties>
</contributor>
</contributors>
环境设置
Issue Management
定义相关的bug跟踪系统,如bugzilla,testtrack,clearQuest等
<issueManagement>
<system>Bugzilla</system>
<url>http://127.0.0.1/bugzilla</url>
</issueManagement>
Continuous Integration Management
连续整合管理,基于triggers或者timings
<ciManagement>
<system>continuum</system>
<url>http://127.0.0.1:8080/continuum</url>
<notifiers>
<notifier>
<type>mail</type>
<sendOnError>true</sendOnError>
<sendOnFailure>true</sendOnFailure>
<sendOnSuccess>false</sendOnSuccess>
<sendOnWarning>false</sendOnWarning>
<configuration><address>[email protected]</address></configuration>
</notifier>
</notifiers>
</ciManagement>
Mailing Lists
<mailingLists>
<mailingList>
<name>User List</name>
<subscribe>[email protected]</subscribe>
<unsubscribe>[email protected]</unsubscribe>
<post>[email protected]</post>
<archive>http://127.0.0.1/user/</archive>
<otherArchives>
<otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive>
</otherArchives>
</mailingList>
</mailingLists>
SCM
软件配置管理,如cvs 和svn
<scm>
<connection>scm:svn:http://127.0.0.1/svn/my-project</connection>
<developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection>
<tag>HEAD</tag>
<url>http://127.0.0.1/websvn/my-project</url>
</scm>
Repositories
配置同setting.xml中的开发库
Plugin Repositories
配置同 repositories
Distribution Management
用于配置分发管理,配置相应的产品发布信息,主要用于发布,在执行mvn deploy后表示要发布的位置
1 配置到文件系统
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>file://${basedir}/target/deploy</url>
</repository>
</distributionManagement>
2 使用ssh2配置
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>scp://sshserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
3 使用sftp配置
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>sftp://ftpserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
4 使用外在的ssh配置
编译扩展用于指定使用wagon外在ssh提供,用于提供你的文件到相应的远程服务器。
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>scpexe://sshserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>1.0-alpha-6</version>
</extension>
</extensions>
</build>
5 使用ftp配置
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>ftp://ftpserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0-alpha-6</version>
</extension>
</extensions>
</build>
repository 对应于你的开发库,用户信息通过settings.xml中的server取得
Profiles
类似于settings.xml中的profiles,增加了几个元素,如下的样式:
<profiles>
<profile>
<id>test</id>
<activation>...</activation>
<build>...</build>
<modules>...</modules>
<repositories>...</repositories>
<pluginRepositories>...</pluginRepositories>
<dependencies>...</dependencies>
<reporting>...</reporting>
<dependencyManagement>...</dependencyManagement>
<distributionManagement>...</distributionManagement>
</profile>
</profiles>