How to create a Maven web app and deploy to Tomcat - fast
原文地址: http://www.blogjava.net/sealyu/archive/2010/01/08/308706.html
Procedure
Prerequisites and Assumptions
- Maven is already installed
- A local instance of Tomcat is already installed and configured to run on port 8080
- Optional - Eclipse is installed
Step One - Prepare the Tomcat Manager application
In order to deploy a web app to your Tomcat server, you will need to ensure that you can access the Tomcat Manager application at:http://localhost:8080/manager/html
. Typically, you just need to ensure that your <tomcat>/conf/tomcat-users.xml file has the following defined:
<?xml version='1.0' encoding='utf-8'?> |
<tomcat-users> |
<role rolename="manager"/> |
<role rolename="admin"/> |
<user username="admin" password="admin" roles="admin,manager"/> |
</tomcat-users> |
In this case, we will be logging in to the Tomcat Manager app using:
| username | admin |
|---|---|
| password | admin |
Step Two - Create a New Web App Using Maven
Next, we will use a Maven archetype to generate a new web application project.
Assuming that you will primarily use Eclipse as your IDE, you may wish to start the project within Eclipse. We'll start the project within Eclipse and then use Maven to fill the project in with the proper Maven web app structure.
- In Eclipse create a new General project. New > Project... > General > Project
- Project name: "sw" (name it what you wish, but remember to replace 'sw' with your project name in all instances where that appears in this document from here on out.)
The steps above just create a General project in your Eclipse workspace (e.g. a folder with a .project settings file inside of it).
Next, open a command prompt, cd into the 'sw' project directory, and then execute the following Maven command (all on one line):
mvn archetype:create |
-DgroupId=com.burlesontech.sw |
-DartifactId=webapp |
-DarchetypeArtifactId=maven-archetype-webapp |
You project will now have the following structure:
- sw
- webapp
- src
- main
- resources
- webapp
- WEB-INF
- web.xml
- index.jsp
- WEB-INF
- main
- pom.xml
- src
- .project
- webapp
In Eclipse, right-click on the project and select Refresh to see this stuff within Eclipse. (Note that the .project file will typically not appear within Eclipse, but it is there.)
Step Three - Define Your Tomcat Server in Maven Settings
Open your Maven settings.xml file (e.g. C:"Documents and Settings"Administrator".m2"settings.xml) and add a server 'myserver' with the credentials for logging into the Tomcat Manager application:
<settings> |
<servers> |
<server> |
<id>myserver</id> |
<username>admin</username> |
<password>admin</password> |
</server> |
</servers> |
... |
Step Four - Point Your Pom to Your Tomcat Server
Open the pom.xml file in the 'sw' project and replace the <build> section so that it looks like this:
<build> |
<finalName>sw</finalName> |
<plugins> |
<plugin> |
<groupId>org.codehaus.mojo</groupId> |
<artifactId>tomcat-maven-plugin</artifactId> |
<configuration> |
<server>myserver</server> |
<path>/sw</path> |
</configuration> |
</plugin> |
</plugins> |
</build> |
Here, we have added the Tomcat plugin for Maven. Note that the <configuration> section needs to point to the server you defined in settings.xml ('myserver'). The <finalName> and the <path> are used to tell the web context that you want to deploy to. In this case, we'll be able to access our application athttp://localhost:8080/sw
.
Step Five - Build and Deploy the Web App
On a command prompt, you can now cd into the sw/webapp directory where the project pom exists. The execute the following command:
mvn tomcat:deploy |
If you get a BUILD SUCCESSFUL message, you should then be able to access your web application at http://localhost:8080/sw/
.
You should see "Hello World!" in your web browser (from the index.jsp page). Now you're all set and ready to start building the next killer web app!
If you try to deploy again with the same command, you will likely get a FAIL message because the application already exists at the path. For successive deployments, use the following command instead:
mvn tomcat:redeploy |
Next, you may want to enable log4j logging for your new application; check out How to setup Log4j in a web app - fast.
How to create a Maven web app and deploy to Tomcat - fast的更多相关文章
- JavaEE开发基于Eclipse的环境搭建以及Maven Web App的创建
本篇博客就完整的来聊一下如何在Eclipse中创建的Maven Project.本篇博客是JavaEE开发的开篇,也是基础.本篇博客的内容干货还是比较多的,而且比较实用,并且都是采用目前最新版本的工具 ...
- JavaEE开发之基于Eclipse的环境搭建以及Maven Web App的创建
本篇博客就完整的来聊一下如何在Eclipse中创建的Maven Project.本篇博客是JavaEE开发的开篇,也是基础.本篇博客的内容干货还是比较多的,而且比较实用,并且都是采用目前最新版本的工具 ...
- eclipse创建maven web app
1 这个功能是由eclipse的插件maven archetype plugin支持的 2 创建过程 File->New->Maven Project 选择archetype为maven- ...
- 【IDEA使用技巧】(5) —— IntelliJ IDEA集成Tomcat部署Maven Web项目
1.IntelliJ IDEA集成Tomcat部署Maven Web项目 1.1.IDEA构建Maven Web项目 使用IDEA来创建一个简单的Hello World的Maven Web项目,并使用 ...
- 004.Create a web app with ASP.NET Core MVC using Visual Studio on Windows --【在 windows上用VS创建mvc web app】
Create a web app with ASP.NET Core MVC using Visual Studio on Windows 在 windows上用VS创建mvc web app 201 ...
- Java create azure web app
create a certificate <java-install-dir>/bin/ keytool -genkey -alias <keystore-id> -keyst ...
- Create an ASP.NET Core web app in Visual Studio Code
https://www.microsoft.com/net/core#windowscmd https://download.microsoft.com/download/B/9/F/B9F1AF57 ...
- 亲手使用Sencha Touch + phonepag开发Web APP随笔 -- 第一个APP
参考博文: [Phonegap+Sencha Touch] 移动开发1.准备工作 [Phonegap+Sencha Touch] 移动开发2.PhoneGap/Cordova初步使用 经过差不多1 ...
- Java Web学习系列——Maven Web项目中集成使用Spring、MyBatis实现对MySQL的数据访问
本篇内容还是建立在上一篇Java Web学习系列——Maven Web项目中集成使用Spring基础之上,对之前的Maven Web项目进行升级改造,实现对MySQL的数据访问. 添加依赖Jar包 这 ...
随机推荐
- java基础14 多态(及关键字:instanceof)
面向对象的三大特征: 1.封装 (将一类属性封装起来,并提供set()和get()方法给其他对象设置和获取值.或者是将一个运算方法封装起来,其他对象需要此种做运算时,给此对象调用) 2.继承 ...
- Jmeter-----保存到响应文件
在jmeter中使用保存响应到文件 ------适用于非GUI模式执行脚本时,无法查看报错的信息. 1.添加组件: 2.各个配置项说明: 1.名称:即组件在整个测试计划中的名称显示,建议设置为用意义的 ...
- rmdir命令
rmdir命令用来删除空目录.当目录不再被使用时,或者磁盘空间已到达使用限定值,就需要删除失去使用价值的目录.利用rmdir命令可以从一个目录中删除一个或多个空的子目录.该命令从一个目录中删除一个或多 ...
- 用numpy计算成交量加权平均价格(VWAP),并实现读写文件
VWAP(Volume-Weighted Average Price,成交量加权平均价格)是一个非常重要的经济学量,它代表着金融资产的“平均”价格.某个价格的成交量越高,该价格所占的权重就越大.VWA ...
- day4迭代器&生成器&正则表达式
一.迭代器 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不能后退,不过这也没什么,因为人们很少在迭代途中后退.另外,迭代器的一大优点 ...
- Linux性能工具
Brendan Gregg 目前是 Netflix 的高级性能架构师 ,他在那里做大规模计算机性能设计.分析和调优.他是<Systems Performance>等技术书的作者,因在系统管 ...
- 使用360对app安全进行加固
在写了第一个app之后,打算上架到各个渠道看看,无意间看到了360的app加固工具 http://jiagu.360.cn/ 自己体验了一把,加固过程很傻瓜化, 加固好了之后,还要对app进行二次签名 ...
- 【LOJ】#2586. 「APIO2018」选圆圈
题解 不旋转坐标系,TLE,旋转坐标系,最慢一个点0.5s--maya,出题人数据水平很高了-- 好吧,如果你不旋转坐标系,写一个正确性和复杂度未知的K - D树,没有优化,你可以得到87分的好成绩 ...
- thinkjs REST API的跨域设置
用thinkjs也有一小段时间了,和其它国产框架一样,起初是处于观望态度.当然我最先的选择也不是thinkjs而是选的express,用到后面发现实现一个能让自己用着比较顺手的博客还是一件蛮困难或者说 ...
- MySQL 5.7 安装完成后,首次登陆的几个问题
Server:CentOS 7.0 MySQL : 5.7.20 MySQL Community Server (GPL) 1.首次登陆后修改密码: 根据安装时的选择不同,有mysqld_safe用m ...