IntelliJ IDEA使用maven实现tomcat的热部署

本文介绍如何通过配置Tomcat的用户角色及使用Maven插件实现项目的远程部署过程,包括配置tomcat-users.xml文件和pom.xml文件的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在tomcat的conf目录 tomcat-users.xml配置以下内容(<tomcat-users>标签内</tomcat-users>),用于部署:

<role rolename="manager"/>       
<role rolename="manager-gui"/>       
<role rolename="admin"/>       
<role rolename="admin-gui"/>     
<role rolename="manager-script"/>      
<user username="tomcat" password="tomcat" roles="admin-gui,admin,manager-gui,manager,manager-script"/  

启动tomcat,访问 http:ip:8080/manager 验证tomcat用户是否配置成功



在maven工程的pom.xml中配置插件

            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <port>8080</port>
                    <path>/mvc</path>
                    <url>http://192.168.43.128:8080/manager/text</url>
                    <username>tomcat</username>
                    <password>tomcat</password>
                </configuration>
            </plugin>

运行配置

点击Run-->Edit Configurations

点击+号,选择Maven ,

输入信息

Name 给运行配置取的名称

Working directory(工程目录)

Command line 命令 tomcat7:deploy 或 tomcat7:redeploy


点击确定,保存。


在Run菜单下找到刚做好的配置,运行

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for org.jstudioframework:jstudio-mvc:war:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.tomcat.maven:tomcat7-maven-plugin is missing. @ line 91, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building jstudio-mvc 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:redeploy (default-cli) @ jstudio-mvc >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ jstudio-mvc ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ jstudio-mvc ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ jstudio-mvc ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\JstudioProject1\JstudioMvc\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ jstudio-mvc ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.14:test (default-test) @ jstudio-mvc ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ jstudio-mvc ---
[INFO] Packaging webapp
[INFO] Assembling webapp [jstudio-mvc] in [E:\JstudioProject1\JstudioMvc\target\jstudio-mvc-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [E:\JstudioProject1\JstudioMvc\src\main\webapp]
[INFO] Webapp assembled in [177 msecs]
[INFO] Building war: E:\JstudioProject1\JstudioMvc\target\jstudio-mvc-1.0-SNAPSHOT.war
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored 
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:redeploy (default-cli) @ jstudio-mvc <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:redeploy (default-cli) @ jstudio-mvc ---
[INFO] Deploying war to http://192.168.43.128:8080/mvc  
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Uploading: http://192.168.43.128:8080/manager/text/deploy?path=%2Fmvc&update=true
Uploaded: http://192.168.43.128:8080/manager/text/deploy?path=%2Fmvc&update=true (7445 KB at 7083.3 KB/sec)

[INFO] tomcatManager status code:200, ReasonPhrase:OK
[INFO] OK - Deployed application at context path /mvc
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.720s
[INFO] Finished at: Sun Jul 23 19:35:01 CST 2017
[INFO] Final Memory: 15M/322M
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0

发布成功。

在tomcat的manager可以看到新发布的应用。


方法2:



这几个标红的菜单都能远程发布

IntelliJ IDEA实现Tomcat服务器的集成以及应用的热部署,可以通过以下步骤进行: 参考资源链接:[IDEA使用技巧与配置详解](https://wenku.youkuaiyun.com/doc/6bx29pr0h1?spm=1055.2569.3001.10343) 首先,确保已经安装了Tomcat插件。你可以在IDEA的'File' -> 'Settings' -> 'Plugins'中搜索并安装Tomcat或Jetty插件。 接着,配置Tomcat服务器的启动环境。这涉及到在'Run/Debug Configurations'中创建新的服务器配置。选择相应的Tomcat版本,并指定应用的部署路径、端口以及上下文路径。 为了方便调试,可以在项目的'pom.xml'中配置maven-war-plugin插件,确保在构建war包时自动包含最新的更改,这样可以避免每次都需要手动重新打包war文件。 对于更新功能,虽然IDEA自身支持项目文件的自动编译,但是对于热部署(即部署后不重启服务器直接更新应用),则需要借助JRebel等热部署插件。JRebel插件可以在IDEA插件市场中安装,并在'Run/Debug Configurations'中配置使用。 最后,确保IDEA的'Build, Execution, Deployment' -> 'Deployment'中配置的本地服务器路径正确无误,并在'Build, Execution, Deployment' -> 'Compiler'中开启自动编译选项,这样在代码更改后IDEA会自动编译并通知Tomcat进行热部署。 通过以上步骤,你可以在IntelliJ IDEA实现Tomcat服务器的集成以及应用的热部署,提高开发效率并减少部署重启的时间。关于更多IDEA使用技巧和配置,可以参考《IDEA使用技巧与配置详解》一书,它详细讲解了IDEA的高级功能和最佳实践,帮助你更深入地掌握这一强大的开发工具。 参考资源链接:[IDEA使用技巧与配置详解](https://wenku.youkuaiyun.com/doc/6bx29pr0h1?spm=1055.2569.3001.10343)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值