|
<%@ :针对maven项目,若想让项目也能够自动化部署到tomcat中,需要通过maven自动化部署项目到tomcat中,配置方式:
2.1:第一步:配置tomcat访问权限配置是tomcat安装目录下conf文件夹中的tomcat-user.xml文件中配置,

具体配置如下:
|
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<tomcat-users>
<role rolename="admin"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="admin" roles="admin,manager,manager-gui,manager-script"/>
</tomcat-users>
|
2.2:在maven配置文件中配置tomcatserver
安装过maven的朋友们应该都知道maven的配置文件,找到maven的settings.xml配置文件,找到servers,然后配置tomcatserver,具体配置如下:

内容:
|
<servers>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
-->
<server>
<id>tomcat</id>
<username>admin</username>
<password>admin</password>
</server>
</servers >
|
2.3:项目的pom.xml中配置tomcat-maven-plugin插件:
打开项目下的pom.xml配置文件,找到plugins标签,我们需要在那里配置tomcat-maven-plugin插件,从网上搜索了一些配置方法,发现有两种不同的配置,分界点是根据tomcat的版本来区分的,tomcat7需要使用新版本,新版本的groupId由org.codehaus.mojo改为org.apache.tomcat.maven,新版本同时也支持tomcat6,接下来的配置我就使用了新版本的配置,具体参考:
|
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<fork>true</fork>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<additionalProjectnatures>
<projectnature>
org.springframework.ide.eclipse.core.springnature
</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>
org.springframework.ide.eclipse.core.springbuilder
</buildcommand>
</additionalBuildcommands>
<downloadSources>false</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<wtpversion>1.5</wtpversion>
</configuration>
</plugin>
<!-- 要加上下面的一句,否则执行:mvn package -Dmaven.test.skip=true的时候会报错 -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://127.0.0.1:8080/manager</url>
<server>tomcat</server>
<username>admin</username>
<password>admin</password>
<!-- <update>true</update> -->
<path>/app-tpl-webapp</path>
</configuration>
</plugin>
</plugins>
</build>
|
注意:这里的path的值就是最后发布后的文件名称。
配置参见:http://portlandgo.blog.163.com/blog/static/218936024201433032857104/
最后进入上面pom.xml所在位置,打开所属pom.xml下的cmd命令行窗口,在命令中输入:mvn tomcat6:redeploy

最后发现:

其它参考网站:http://www.cnblogs.com/xyb930826/p/5725340.html
其它参考内容:http://www.cnblogs.com/AloneSword/p/4100072.html
Maven已经是Java的项目管理标配,如何在JavaEE开发使用Maven调用Web应用,是很多同学关心的问题。本文将介绍,Maven如何介绍Tomcat插件。
Maven Tomcat插件现在主要有两个版本,tomcat-maven-plugin和tomcat7-maven-plugin,使用方式基本相同。
tomcat-maven-plugin 插件官网:http://mojo.codehaus.org/tomcat-maven-plugin/plugin-info.html。
tomcat7-maven-plugin 插件官网:http://tomcat.apache.org/maven-plugin.html。
tomcat-maven-plugin 插件使用
配置
在pom.xm 加入以下xml。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<path>/wp</path>
<port>8080</port>
<uriEncoding>UTF-8</uriEncoding>
<url>http://localhost:8080/manager/html</url>
<server>tomcat6</server>
</configuration>
</plugin>
简要说明一下:
path 是访问应用的路径
port 是tomcat 的端口号
uriEncoding URL按UTF-8进行编码,这样就解决了中文参数乱码。
Server指定tomcat名称。
配置就这么简单,基本搞掂,下面看看如何使用。
插件运行
如果Eclipse安装了Maven插件,选 择pom.xml文件,击右键——>选择 Run As——> Maven build 。
如果是第一次运行,会弹出下面对话框。在Goals框加加入以下命令: tomcat:run
这样Tomcat 插件就可以运行。
下面介绍几个常用的Goal
|
命令
|
描述
|
|
tomcat:deploy
|
部署一个web war包
|
|
tomcat:reload
|
重新加载web war包
|
|
tomcat:start
|
启动tomcat
|
|
tomcat:stop
|
停止tomcat
|
|
tomcat:undeploy
|
停止一个war包
|
|
tomcat:run
|
启动嵌入式tomcat ,并运行当前项目
|
tomcat7-maven-plugin 使用
配置
两个插件使用方法基本一样,同样需要在pom.xml引用该插件,需要增加以下配置
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>9090</port>
<path>/mgr</path>
<uriEncoding>UTF-8</uriEncoding>
<finalName>mgr</finalName>
<server>tomcat7</server>
</configuration>
</plugin>
具体配置一样。
插件使用
在这里要注意一下,该插件命名方式有些不同,比如启动tomcat,对应的目标命令是: tomcat7:run ,同样,其它命令也是这样,需要更改为:tomcat7:<插件执行点>
OK,配置就这么简单,如果需要在tomcat 跟踪联调,可以用Dubug 方式启动maven命令。如下图
- Jenkins自动构建gitlab项目(jenkins+maven+giltlab+tomcat)
环境准备: System:CentOS 7.3 (最小化安装) JDK: 8u161 (1.8_161) tomcat: 8.5.29 Jenkins: Jenkins 2.107.1 Gitlab: ...
- IDEA里面maven项目使用maven插件tomcat启动项目
1.首先在pom.xml添加tomcat插件依赖: <?xml version="1.0" encoding="UTF-8"?> <proje ...
- 解决Maven管理项目update Maven时,jre自动变为1.5
本文为博主原创,未经允许不得转载: 在搭建一个maven web项目时,项目已经按步骤搭建完好,之后项目上就报了一个错误. 在控制台看到错误提示如下:Dynamic Web Module 3.0 re ...
- 一台电脑上配置多个tomcat同时运行
好使 1 1.配置运行tomcat 首先要配置java的jdk环境,这个就不在写了 不懂去网上查查,这里主要介绍再jdk环境没配置好的情况下 如何配置运行多个tomcat 2.第一个tomcat: ...
- 如何再一台电脑上配置多个tomcat同时运行
1.配置运行tomcat 首先要配置java的jdk环境,这个就不在谢了 不懂去网上查查,这里主要介绍再jdk环境没配置好的情况下 如何配置运行多个tomcat 2.第一个tomcat: 找到&qu ...
- 修改Tomcat Connector运行模式,优化Tomcat运行性能
Tomcat是一个小型的轻量级应用服务器,也是JavaEE开发人员最常用的服务器之一.不过,许多开发人员不知道的是,Tomcat Connector(Tomcat连接器)有bio.nio.apr三种运 ...
- 修改 Tomcat Connector运行模式 优化Tomcat运行性能
omcat是一个小型的轻量级应用服务器,也是JavaEE开发人员最常用的服务器之一.不过,许多开发人员不知道的是,Tomcat Connector(Tomcat连接器)有bio.nio.apr三种运行 ...
- Linux部署java和tomcat的运行环境
Linux部署java和tomcat的运行环境 1.上传下载的jdk的rpm包和tomcat的tar包,我是放到/opt目录了,文件直接去官网下载即可. 2.如果之前安装过其他版本的jdk,最好先现在 ...
- Eclipse+Maven+JDK+tomcat搭建java的开发环境
由于最近有几个同事都在学习java方面的东西,所以我写个博文做下笔记,其中遇到过很多个坑,这里就不多说了 首先,我用的是Eclipse+Maven的组合,用Ecplise是周边java开发的同事用这个 ...
随机推荐
- 阿里云在RSAC 2018上宣布 将在西雅图建立安全实验室
日前,2018年度的RSA Conference全球信息安全大会在美国加州旧金山市召开.作为全球三大云计算服务商之一,阿里云携3款全新安全产品亮相,并宣布今年将在西雅图设立全新的安全实验室,整合全球安 ...
- 初学Servlet之继承GenericServlet
package app01a;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.GenericSer ...
- [ Java学习基础 ] String、StringBuffer、StringBuilder比较学习
首先讲获得字符串对象的方式有两种,一种是直接使用字符串常量,一种是使用new关键字创建,但它们之间是有一些区别,如下运行实例: String s1 = new String("Hello&q ...
- Java IO(二)
上一节我们说到通过File访问文件,但是我们访问文件的最终目的都是访问文件中的内容,那么这个时候我们就需要使用到的一个类就是:RandomAccessFile. 此类的定义如下: public cla ...
- Error:ivalue require as left operant of assignment
Error:ivalue require as left operant of assignment 解答:该错误的意思是左操作数必须为左值,这个发生错误的原因在于赋值符号的左边不能是已确定的值,如: ...
- [Codeforces 933B]A Determined Cleanup
Description 题库链接 给你两个正整数 \(p,k\) ,询问是否能够构造多项式 \(f(x)=\sum\limits_{i=0}^{d-1}a_ix^i\) ,使得存在多项式 \(q(x) ...
- hdu 5115(2014北京—dp)
题意: 有一排狼,每只狼有一个伤害A,还有一个伤害B.杀死一只狼的时候,会受到这只狼的伤害A和这只狼两边的狼的伤害B的和.如果某位置的狼被杀,那么杀它左边的狼时就会收到来自右边狼的B,因为这两只狼是相 ...
- Vegas Pro 15软件界面对比
大家都知道Vegas是一款专业的视频制作软件,而新版的VEGAS Pro 15更是专业性十足.好了,废话不多说,接下来小编就带大家具体的看一下Vegas 15界面都有哪些更新吧! 一.软件图标 图1: ...
- GNS3 1.4.0b3 MSTP多生成树配置实验
一.实验目标 掌握MSTP多生成树配置,VLAN配置,trunk配置,etherchannel配置 二.实验平台 系统:WIN7以上windows,X64版本.CPU支持虚拟化,并在BIOS中开启虚拟 ...
- Json数组删除
有一个json数组,{'people':[{'name':'jetty','sex':'男'},{'name':'lily','sex':'女'}]} 有一个json:var aa={'name':' ...
|