springboot聚合项目打包

一、启动脚本start.sh

#!/bin/sh
# 启动 jar 运行
# 项目部署目录
projectDir=/root/jar/yubin
# 项目运行 jar 名称
jarName="yubin.jar"
# 这里的-x 参数判断${logDir}是否存在并且是否具有可执行权限
# 脚本日志目录
# logDir=/usr/local/java-jar/base-server
logDir=/root/jar/yubin
logFile=catalina.out
if [ ! -x "${logDir}" ]; then
  sudo mkdir -p "${logDir}"
fi
# 判断项目SpringBoot程序是否运行
count=$(ps -ef |grep ${jarName} |grep -v "grep" |wc -l)
if [ ${count} -lt 1 ]; then
    nohup java -jar ${jarName} --spring.profiles.active=dev > $logDir/$logFile 2>>$logDir/$logFile &
else
    echo "程序正在运行中,请先停止......"
fi

二、结束脚本shutdown.sh

#!/bin/bash
ps -ef|grep fee-rule.jar|grep -v grep|awk '{print $2}'|xargs kill -9
echo "正在停止......"

三、打包

1.父模块pom.xml配置

(1)进行jar包的统一管理;

(2)pom

(3)将build标签以及内部内容全部删除,删除如下内容:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

2.不含启动类的子模块pom.xml

将build标签以及内部内容全部删除即可。

3.含有启动类的子模块pom.xml

(1)将所需引入的子模块通过mvn install打包后以jar包的方式引入。

(2)pom.xml配置,如下:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.wen</groupId>
        <artifactId>wen-boot</artifactId>
        <version>1.0</version>
    </parent>
 
    <artifactId>wen-boot</artifactId>
    <version>1.0</version>
 
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.wen</groupId>
            <artifactId>wen-common</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.wen</groupId>
            <artifactId>wen-system</artifactId>
            <version>${project.version}</version>
        </dependency>
 
    </dependencies>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!-- 指定该Main Class为全局的唯一入口 这里是启动类的地址 -->
                    <mainClass>com.wen.WenBootApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <!-- maven项目中src源代码下的xml等资源文件编译进classes文件夹,
                注意:如果没有这个,它会自动搜索resources下是否有mapper.xml文件,
                如果没有就会报org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pet.mapper.PetMapper.selectByPrimaryKey-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <!--将resources目录下的配置文件编译进classes文件  -->
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>
 
</project>

(3)注意事项
在spring-boot-maven-plugin里的configuration中使用skip标签打出的jar包运行会显示xxx.jar包中没有主清单属性,配置如下:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!-- 指定该Main Class为全局的唯一入口 这里是启动类的地址 -->
                    <mainClass>com.sunyard.WenBootApplication</mainClass>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <!-- maven项目中src源代码下的xml等资源文件编译进classes文件夹,
                注意:如果没有这个,它会自动搜索resources下是否有mapper.xml文件,
                如果没有就会报org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pet.mapper.PetMapper.selectByPrimaryKey-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <!--将resources目录下的配置文件编译进classes文件  -->
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>

如果打包想跳过单元测试,因该使用如下配置:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>2.19.1</version>
   <configuration>
      <skipTests>true</skipTests>
   </configuration>
</plugin>

或者

mvn package -Dmaven.test.skip=true

你可能感兴趣的:(spring,boot,python,后端)