测试环境:
物理机:ubuntu 16.04
虚拟机:centos 7.2
内容比较简单,学习一下Maven部署项目的过程。
1.服务器安装配置jdk和tomcat
scp apache-tomcat-8.5.15.tar.gz root@192.168.100.129:/opt/
scp jdk-8u131-linux-x64.rpm root@192.168.100.129:/opt/
ssh 192.168.100.129
cd /opt
# 安装jdk
rpm -ivh jdk-8u131-linux-x64.rpm
# 解压tomcat
tar -vxzf apache-tomcat-8.5.15.tar.gz
2.配置tomcat服务器
cd /opt/apache-tomcat-8.5.15
# 编辑配置文件
vi conf/tomcat-users.xml
尾部添加如下内容
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="admin" roles="manager-gui,manager-script"/>
3.新建项目maven
编辑pom.xml文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.byhook.maven</groupId>
<artifactId>maven</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>maven Maven Webapp</name>
<url>http://maven.apache.org</url>
<build>
<finalName>maven</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<!--tomcat7 将source和target改为1.7-->
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://192.168.100.129:8080/manager/text</url>
<username>admin</username>
<password>admin</password>
<path>/${project.artifactId}</path>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>8.5.15</version>
</dependency>
</dependencies>
</project>
4.启动tomcat并开启相关端口
cd /opt/apache-tomcat-8.5.15/bin
./startup.sh
# 开启端口
firewall-cmd --add-port=8080/tcp --permanent
# 加载配置
firewall-cmd --reload
# 查看端口是否开启
firewall-cmd --query-port=8080/tcp
现在直接部署可能会出现403错误
Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project maven: Tomcat return http status error: 403
需要解除IP限制
vi /opt/apache-tomcat-8.5.15/webapps/manager/META-INF/context.xml
末尾改正为:
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="192\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
</Context>
5.部署项目
mvn clean install tomcat7:deploy
6.访问一下
以上记录,亲测可行!
参考:
http://blog.csdn.net/ab7253957/article/details/72770587
https://my.oschina.net/jerryhu/blog/295279
网友评论