对于非Maven的web项目,有时候我们想不时常通过打war包、拷贝war包、启动tomcat来运行项目、这时候我们可以通过以下方式来进行配置:

1.1:创建web工程。工程结构如下:

1.2、其中index.jsp的内容如下:

<%@ :针对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的值就是最后发布后的文件名称。

Tomcat6的url配置必须为http://localhost:8080/manager 后面不能加html或者text,不然报403错误。

Tomcat7的url配置必须为http://127.0.0.1:8080/manager/text text不能替换为html,不然报403错误。

配置参见: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命令。如下图

tomcat自动运行磁盘任意位置上的项目、使用Maven对tomcat进行自动部署的更多相关文章

  1. 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: ...

  2. IDEA里面maven项目使用maven插件tomcat启动项目

    1.首先在pom.xml添加tomcat插件依赖: <?xml version="1.0" encoding="UTF-8"?> <proje ...

  3. 解决Maven管理项目update Maven时,jre自动变为1.5

    本文为博主原创,未经允许不得转载: 在搭建一个maven web项目时,项目已经按步骤搭建完好,之后项目上就报了一个错误. 在控制台看到错误提示如下:Dynamic Web Module 3.0 re ...

  4. 一台电脑上配置多个tomcat同时运行

    好使 1 1.配置运行tomcat 首先要配置java的jdk环境,这个就不在写了  不懂去网上查查,这里主要介绍再jdk环境没配置好的情况下 如何配置运行多个tomcat 2.第一个tomcat: ...

  5. 如何再一台电脑上配置多个tomcat同时运行

    1.配置运行tomcat 首先要配置java的jdk环境,这个就不在谢了  不懂去网上查查,这里主要介绍再jdk环境没配置好的情况下 如何配置运行多个tomcat 2.第一个tomcat: 找到&qu ...

  6. 修改Tomcat Connector运行模式,优化Tomcat运行性能

    Tomcat是一个小型的轻量级应用服务器,也是JavaEE开发人员最常用的服务器之一.不过,许多开发人员不知道的是,Tomcat Connector(Tomcat连接器)有bio.nio.apr三种运 ...

  7. 修改 Tomcat Connector运行模式 优化Tomcat运行性能

    omcat是一个小型的轻量级应用服务器,也是JavaEE开发人员最常用的服务器之一.不过,许多开发人员不知道的是,Tomcat Connector(Tomcat连接器)有bio.nio.apr三种运行 ...

  8. Linux部署java和tomcat的运行环境

    Linux部署java和tomcat的运行环境 1.上传下载的jdk的rpm包和tomcat的tar包,我是放到/opt目录了,文件直接去官网下载即可. 2.如果之前安装过其他版本的jdk,最好先现在 ...

  9. Eclipse+Maven+JDK+tomcat搭建java的开发环境

    由于最近有几个同事都在学习java方面的东西,所以我写个博文做下笔记,其中遇到过很多个坑,这里就不多说了 首先,我用的是Eclipse+Maven的组合,用Ecplise是周边java开发的同事用这个 ...

随机推荐

  1. TCP三次握手详解及释放连接过程

    TCP在传输之前会进行三次沟通,一般称为"三次握手",传完数据断开的时候要进行四次沟通,一般称为"四次挥手". 两个序号和三个标志位: (1)序号:seq序号, ...

  2. 【NOIP 2017】列队

    Description Sylvia 是一个热爱学习的女♂孩子. 前段时间,Sylvia 参加了学校的军训.众所周知,军训的时候需要站方阵. Sylvia 所在的方阵中有n×m名学生,方阵的行数为 n ...

  3. [JSOI2008]球形空间产生器

    Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...

  4. ●BZOJ 3831 [Poi2014]Little Bird

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3831 题解: 单调队列优化DP 定义 F[i] 为到达第i课树的疲劳值. 显然最暴力的转移就 ...

  5. Android技术分享-文字转语音并朗读

    Android技术分享-文字转语音并朗读 最近在做一个项目,其中有一个功能是需要将文本转换成语音并播放出来.下面我将我的做法分享一下. 非常令人开心的是,Android系统目前已经集成了TTS,提供了 ...

  6. Python中模块之collections系列

    collection系列功能介绍 1. 常用的集中类 1. Counter(计数器) 计数器的常用方法如下: 创建一个字典计数器 格式:collections.Counter(obj) 例如:prin ...

  7. (MariaDB)开窗函数用法

    本文目录: 1.1 窗口和开窗函数简介 1.2 OVER()语法和执行位置 1.3 row_number()对分区排名 1.4 rank()和dense_rank() 1.5 percent_rank ...

  8. redux 最简例子

    方便初学redux的同学学习,这里是最简单的redux例子 1 import React, {Component, PropTypes} from 'react' 2 import ReactDOM ...

  9. 3.5 find() 判断是否存在某元素

    vector 判断是否存在某元素: if(find(A.begin(), A.end(), A[i]) != A.end()){ // 若存在 A[i] // find() 返回一个指针 }

  10. 解释session

    我理解的session就是,多个页面都要使用某一个或一些数据,这时就可以用session,将数据暂时保存起来,这样其他的页面开启session,就能将那些数据拿出来使用.