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包 这 ...
随机推荐
- P3960 列队
这是NOIP 2017最后一道题 不知道这道题有没有人代码写的和我一样麻烦. Solution 30分暴力 维护每行每列的元素. 每次删除一个元素的时候, 需要修改一行一列 因此复杂度上界\(O(nm ...
- 简单优化:Zipalign
Android SDK中包含一个“zipalign”的工具,它能够对打包的应用程序进行优化.在你的应用程序上运行zipalign,使得在运行时Android与应用程序间的交互更加有效率.因此,这种方式 ...
- 【PAT】1010. 一元多项式求导 (25)
1010. 一元多项式求导 (25) 设计函数求一元多项式的导数.(注:xn(n为整数)的一阶导数为n*xn-1.) 输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数 ...
- linux中top命令
经常用到top命令,也就简单看看进程多不多,卡不卡, 这次在网上找到一个归纳总结的,以供参考. 简介 top 命令是 Linux 下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于 ...
- SQL1:基础
1.SQL命令类型: 1)DDL:CREATE TABLE/INDEX/VIEW ; ALTER TABLE/INDEX/VIEW ; DROP TABLE/INDEX 2)DML:INSERT,UP ...
- PIPESTATUS(bash) + pipefail(ksh)
I have two processes foo and bar, connected with a pipe: $ foo | bar bar always exits 0; I'm interes ...
- shell中的条件判断if和测试
(一)条件判断 if 中-z 到 -d 的意思 [ -a file ] 若file存在,则为真. [ -b file ] 若file存在且是一个块特殊文件,则为真. [ -c file ] 若file ...
- 01-学前入门概念:.net与c#
.Net是由(.Net 平台和.Net FrameWork框架)这两部分组成. .Net FrameWork是由(CLR公共语言运行时和.Net 类库组成). .Net FrameWork框架是.Ne ...
- HDU 6134 Battlestation Operational(莫比乌斯反演)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6134 [题目大意] 求$\sum_{i=1}^{n}{\sum_{j=1}^{i}\lceil{\ ...
- 最封闭的开源系统,话说Android的八宗罪
最封闭的开源系统,话说Android的八宗罪 http://www.ifanr.com/9833 Android 分裂的多面性 http://tech.cncms.com/shouji/android ...