多模块项目打包
父工程 pom.xml
<packaging>pom</packaging>
打包方式指定为pom
<modules>
<module>xxx1</module>
<module>xxx2</module>
</modules>
添加子模块
父模块打包插件
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<skipTests>true</skipTests> <!--默认关掉单元测试 -->
</configuration>
</plugin>
</plugins>
</build>
子模块中只需要在web模块中添加打包插件,其它不需要
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 指定该Main Class为全局的唯一入口 -->
<mainClass>com.os467.FerryBackendApplication</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<!--可以把依赖的包都打包到生成的Jar包中-->
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
需要指定启动类
所有子模块都需要打包为jar
添加到所有子模块pom
<packaging>jar</packaging>
maven的Lifecycle中选择package即可
线上java环境配置
设置环境变量
[root@localhost java]# vi /etc/profile
在profile中添加如下内容
#set java environment
JAVA_HOME=/usr/java/jdk1.7.0_79
JRE_HOME=/usr/java/jdk1.7.0_79/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
让修改生效
[root@localhost java]# source /etc/profile
验证JDK有效性
[root@localhost java]# java -version
运行jar
java -jar xxx.jar
使用docker部署redis
#可以先看本机是否有redis
ps -ef | grep redis
systemctl restart redis
先安装docker环境
docker pull redis
mkdir -p /usr/local/docker/redis
mkdir -p /usr/local/docker/redis/data
touch /usr/local/docker/redis/redis.conf
#编辑配置文件
vim /usr/local/docker/redis/redis.conf
#需要密码则打开
requirepass 123456
运行
docker run -id -p 6380:6379 --name=redis --restart=always -v /usr/local/docker/redis/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/redis/data:/data -d redis redis-server /etc/redis/redis.conf
docker部署mysql
#拉取服务
docker pull mysql
#挂载镜像
docker run -id -p 3307:3306 --name=mysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root mysql:5.7
#进入镜像内部
docker exec -it mysql /bin/bash
#修改mysql密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root密码';
#修改远程密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root密码';
#刷新
flush privileges;
查看服务器开放端口
netstat -talnp
服务器安装mysql
可以不看
#检查之前是否安装
find / -name mysql
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
pwd /opt/core/mysql
#解压
tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
创建数据存放目录
mkdir -p /opt/data/mysqldata
cd /opt/data
chown -R root:root mysqldata
#配置mysql
vim /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=root
basedir=/usr/local/mysql
datadir=/opt/data/mysqldata
socket=/tmp/mysql.sock
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_connections=400
innodb_file_per_table=1
lower_case_table_names=1
character_set_server=utf8
symbolic-links=0
[mysqld_safe]
log-error=/opt/data/mysqldata/mysql.err
pid-file=/opt/data/mysqldata/mysql.pid
!includedir /etc/my.cnf.d
初始化数据库
cd /usr/local/mysql/bin/
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/opt/data/mysqldata/ --user=root --initialize
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
#启动mysql
service mysql start
ps -ef|grep mysql
修改mysql密码
cd /usr/local/mysql/bin
mysql -u root -p
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以邮件至 1300452403@qq.com