简介:
在项目中时常需要部署项目,在程序员的工作中大部分时间,不是再解决bug,就是在部署项目的路上,有得时候各种各样的环境,部署时间就占用了一大半。
解决方案:
1.开启tomcat的远程部署,修改服务器上的配置文件,使用idea的tomcat插件实现远程部署项目。
2.使用idea中插件docker,创建Dockerfile 使用idea为我们提供好的一键化配置,也可以实现,在docker运行项目,实现一键部署。
3.使用jenkins自动部署集成工具,来实现部署,例如:代码提交到gitLab,自动触发,编译项目,将编译好的内容部署到指定目录。
今天我就为大家来讲解第一种方案,使用一键idea远程部署到tomcat中启动项目。
一 . 修改服务器上的tomcat配置
1 . 添加,修改tomat/conf/tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="yourname" password="yourpassword" roles="manager-gui,manager-script"/>
2 . 修改部署的ip项目:tomcat/webapps/manager/META-INF/context.xml
将:
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
修改为:
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="^.*$" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
二 . 打开maven下的conf下的settings.xml
修改配置如下:
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<!--有tomcat8插件的仓库-->
<mirror>
<id>artifacts</id>
<name>artifacts maven</name>
<url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
<mirrorOf>*</mirrorOf>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
说明:
因为maven远程仓库中没有tomcat8的插件,所以要配置artifacts仓库!
三 . 修改maven项目中pom.xml
添加如下配置:
1 . 在pom文件中添加从什么地方下载插件配置
<!--这是配置Maven从什么地方下载插件构件(Maven的所有实际行为都由其插件完成)-->
<pluginRepositories>
<pluginRepository>
<id>alfresco-public</id>
<url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
</pluginRepository>
<pluginRepository>
<id>alfresco-public-snapshots</id>
<url>https://artifacts.alfresco.com/nexus/content/groups/public-snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
2 . 配置插件
<!-- 配置Tomcat8插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat8-maven-plugin</artifactId>
<version>3.0-r1655215</version>
<configuration>
<!-- 将IP改为主机IP,其他不变 -->
<url>http://Ip:8080/manager/text</url>
<!-- 项目名称,访问路径为 localhost:8080/projectName -->
<!-- 当设置为 / 时, 即为 localhost:8080/, 但是注意会覆盖ROOT项目 -->
<path>/myproject</path>
<!-- tomcat账号密码 -->
<username>yourname</username>
<password>yourpassword</password>
</configuration>
</plugin>
四 . 部署项目到tomcat中
第一次部署点击:tomcat8:deploy
之后tomcat下webapps有项目了使用:tomcat8:redeploy
出现code 0 部署成功!
可以去服务器上webapps目录中确认,或是获取访问项目地址~到这个就大功告成了!
技术支持:高岳峰,闫宇峰,施凯雷,杨珂
他的个人博客地址:http://120.78.93.197/
这是我的公众号 有最新的it咨询,和个人工作的记录:
这是我的个人微信遇到问题欢迎,提问:
最后加上高质量的淘宝店:如有质量问题随时滴滴我,童叟无欺!