springboot+assembly插件打包

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

提示:这里可以添加本文要记录的大概内容:
个人学习使用。


提示:以下是本篇文章正文内容,下面案例可供参考

一、shell脚本

示例:启动脚本 仅供参考。

  • startup.sh
#!/bin/sh

error_exit ()
{
    echo "ERROR: $1 !!"
    exit 1
}
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
[ ! -e "$JAVA_HOME/bin/java" ] && unset JAVA_HOME


if [ -z "$JAVA_HOME" ]; then
      error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better!"
fi


export SERVER="out-manager"

export JAVA_HOME
export JAVA="$JAVA_HOME/bin/java"
export BASE_DIR=`cd $(dirname $0)/..; pwd`
export CUSTOM_SEARCH_LOCATIONS=file:${BASE_DIR}/conf/
export JASYPT_PASSWORD="sunline"

#===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -Xms1024m -Xmx1024m -Xmn512m"
#JAVA_OPT="${JAVA_OPT} -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext:${BASE_DIR}/plugins/cmdb:${BASE_DIR}/plugins/mysql"


JAVA_OPT="${JAVA_OPT} -Dsystem.basedir=${BASE_DIR}"
JAVA_OPT="${JAVA_OPT} -Dloader.path=${BASE_DIR}/plugins/health -jar ${BASE_DIR}/target/${SERVER}.jar"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
JAVA_OPT="${JAVA_OPT} --spring.config.location=${CUSTOM_SEARCH_LOCATIONS}"
JAVA_OPT="${JAVA_OPT} --logging.config=${BASE_DIR}/conf/log4j2.xml"
JAVA_OPT="${JAVA_OPT} --server.max-http-header-size=524288"
JAVA_OPT="${JAVA_OPT} --jasypt.encryptor.password=${JASYPT_PASSWORD}"

if [ ! -d "${BASE_DIR}/logs" ]; then
  mkdir ${BASE_DIR}/logs
fi

echo "$JAVA ${JAVA_OPT}"


echo "${SERVER} is starting ...."


nohup $JAVA ${JAVA_OPT} ${SERVER} >> /dev/null 2>&1 &
echo "${SERVER} is starting,you can check the ${BASE_DIR}/logs/default.log"

  • shutdown.sh
#!/bin/sh

cd `dirname $0`/../target
target_dir=`pwd`
server_name=out-manager

pid=`ps ax | grep -i ${server_name} | grep ${target_dir} | grep java | grep -v grep | awk '{print $1}'`
if [ -z "$pid" ] ; then
        echo "No ${server_name} running..."
        exit 0;
fi

echo "The ${server_name}(${pid}) is running..."

kill ${pid}

echo "Send shutdown request to ${server_name}(${pid}) OK"
  • startup.bat
@echo off

if not exist "%JAVA_HOME%\bin\java.exe" echo Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! & EXIT /B 1
set "JAVA=%JAVA_HOME%\bin\java.exe"

setlocal enabledelayedexpansion

set BASE_DIR=%~dp0
rem added double quotation marks to avoid the issue caused by the folder names containing spaces.
rem removed the last 5 chars(which means \bin\) to get the base DIR.
set BASE_DIR="%BASE_DIR:~0,-5%"

set CUSTOM_SEARCH_LOCATIONS=file:%BASE_DIR%/conf/


set SERVER=out-manager


set "JAVA_OPT=%JAVA_OPT% -Xms1024m -Xmx1024m -Xmn512m"

set JASYPT_PASSWORD="sunline"

set "JAVA_OPT=%JAVA_OPT% -Dsystem.basedir=%BASE_DIR%"
set "JAVA_OPT=%JAVA_OPT% -Dloader.path=%BASE_DIR%/plugins/health -jar %BASE_DIR%\target\%SERVER%.jar"
set "JAVA_OPT=%JAVA_OPT% --spring.config.location=%CUSTOM_SEARCH_LOCATIONS%"
set "JAVA_OPT=%JAVA_OPT% --logging.config=%BASE_DIR%/conf/log4j2.xml"
set "JAVA_OPT=%JAVA_OPT% --jasypt.encryptor.password=%JASYPT_PASSWORD%"

call "%JAVA%" %JAVA_OPT% %SERVER% %*

pause

  • shutdown.bat
@echo off

if not exist "%JAVA_HOME%\bin\jps.exe" echo Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! & EXIT /B 1

setlocal

set "PATH=%JAVA_HOME%\bin;%PATH%"

set serve_name=out-manager
echo killing %serve_name%

for /f "tokens=1" %%i in ('jps -m ^| find "%serve_name%"') do ( taskkill /F /PID %%i )

echo Done!

二、编写assembly.xml

1.位置

在java和resources的同级目录
在这里插入图片描述

代码如下(示例):

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
    <id>bin</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>true</includeBaseDirectory>

    <files>
        <file>
            <fileMode>775</fileMode>
            <source>target/${project.build.finalName}.jar</source>
            <destName>out-manager.jar</destName>
            <outputDirectory>./target</outputDirectory>
        </file>
    </files>

    <fileSets>
        <fileSet>
            <directory>src/main/resources</directory>
            <outputDirectory>./conf</outputDirectory>
            <includes>
                <include>application.yml</include>
                <include>application-dev.yml</include>
                <include>application-prd.yml</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>src/main/resources/logconf</directory>
            <outputDirectory>./conf</outputDirectory>
            <includes>
                <include>log4j2.xml</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>src/main/resources/mybatis</directory>
            <outputDirectory>./conf</outputDirectory>
            <includes>
                <include>mybatis-config.xml</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>src/main/resources/i18n</directory>
            <outputDirectory>./i18n</outputDirectory>
            <includes>
                <include>*.properties</include>
            </includes>
        </fileSet>
        <fileSet>
            <fileMode>775</fileMode>
            <directory>deploy/bin</directory>
            <includes>
                <include>*.sh</include>
            </includes>
            <outputDirectory>./bin</outputDirectory>
            <lineEnding>unix</lineEnding>
        </fileSet>
        <fileSet>
            <fileMode>775</fileMode>
            <directory>deploy/bin</directory>
            <includes>
                <include>*.bat</include>
            </includes>
            <outputDirectory>./bin</outputDirectory>
            <lineEnding>windows</lineEnding>
        </fileSet>
        <fileSet>
            <directory>deploy/db</directory>
            <outputDirectory>./db</outputDirectory>
        </fileSet>
    </fileSets>
    <!-- start 新增点2: 把配置文件加密jar打出来用于执行执行加密脚本-->
    <dependencySets>
        <dependencySet>
            <outputDirectory>./bin/lib</outputDirectory>
            <scope>runtime</scope>
            <includes>
                <include>org.jasypt:jasypt</include>
            </includes>
        </dependencySet>
    </dependencySets>
</assembly>

2.父级pom文件

代码如下(示例):

<maven.assembly.plugin.version>3.1.1</maven.assembly.plugin.version>

<build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven.compiler.plugin.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>${maven.assembly.plugin.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

子工程项目pom文件

<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>utf-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-assembly-plugin</artifactId>
				<executions>
					<execution>
						<id>distr-assembly</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
						<configuration>
							<descriptors>
								<descriptor>src/main/assembly/assembly.xml</descriptor>
							</descriptors>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>

总结

提示:这里对文章进行总结:
以上就是今天要讲的内容,本文仅仅简单介绍了assembly结合springboot的使用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白努力学java

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值