一、在maven中使用内嵌tomcat部署测试Web应用
只使用最简单的java web作为例子。
此时可以使用maven内嵌的tomcat,中间要用到tomcat-maven-plugin,这里不用设置plugin的repository,它会自动下载tomcat-maven-plugin和tomcat 。
只使用命令
mvn tomcat:run
就可以了。
如果这里我们使用命令
mvn tomcat:deploy
会出现can not invoke tomcat manager的错误。这是因为没有对tomcat manager的设置。
二、在maven中使用外部tomcat部署web应用
此时使用的tomcat为自己安装的,要对tomcat和maven都进行设置。
maven要想链接上tomcat,要有三个步骤:
一是设置tomcat的manager帐号,二是下载可以链接外部tomcat的plugin,三是配置maven setting.xml文件中的server为tomcat的manager。
注意:使用外部的tomcat,要使用最新版本的tomcat6(or7)-maven-plugin。
(1)设置tomcat 的manager帐号
在文件tomcat-path/conf/tomcat-user.xml中加入如下
(2)配置maven setting.xml
对个单个用户,配置的是~/.m2/setting.xml。
(3)下载可以链接外部 tomcat的plugin
在项目的pom.xml中加入plugin.
maven下载plugin和一般库的repo不同,接下来配置repo。
<span style="font-size: 16px;"><!----> <!--if no repository defined, there will be error:--> <!--No plugin found for prefix 'tomcat7' in the current project and in the plugin groups for ..--> <!--from the repository [local],central (https://repo.maven.apache.org.maven2--> <repositories> <repository> <id>people.apache.snapshots</id> <url>http://repository.apache.org/content/groups/snapshots-group</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>apache.snapshots</id> <name>Apache Snapshots</name> <url>http://repository.apache.org/content/groups/snapshots-groups</url> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </span> |