使用assembly打包

1.在pom增加插件

 <build>
        <plugins>
            <!--使用maven-jar-plugin将指定包目录打成单独的jar包 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>*.properties</exclude>
                    </excludes>
                </configuration>
            </plugin>

            <!-- maven 编译插件 maven打包时需要 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <!-- 在构建路径中 指定编译的字符编码 -->
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>

            <!--资源文件拷贝的插件  -->
            <!-- 该插件的作用 主要是处理将 主程序与 运行程序所需的源文件复制到输出编译文件夹中。 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <!-- 在构建路径中 指定源文件编译的字符编码 -->
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <!-- 使用assembly打包后的名字如 service-provider-1.0-SNAPSHOT-release.zip
                        使用ctrl加左键 点进去看${project.artifactId}-${project.version}
                        ${project.artifactId}是当前项目的artifactId和version组合的(service-provider-1.0-SNAPSHOT)加上
                        下面executions的execution的id
                     -->
                    <finalName>${project.build.finalName}</finalName>
                </configuration>
                <executions>  <!--执行器 mvn assembly:assembly-->
                    <execution>
                        <id>release</id><!--名字任意 -->
                        <phase>package</phase><!-- 绑定到package生命周期阶段上 -->
                        <goals>
                            <goal>single</goal><!-- 只运行一次 -->
                        </goals>
                        <configuration>
                            <descriptors> <!--描述文件路径-->
                                <descriptor>src/main/resources/run/assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

2.增加描述文件(这个文件要和pom插件中指定的描述文件路径一致)
assembly.xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0
        http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>release</id>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>src/main/resources</directory>
            <!-- 过滤 -->
            <includes>
                <include>*.properties</include>
            </includes>
            <outputDirectory>/</outputDirectory>
        </fileSet>

        <fileSet>
            <directory>src/main/resources/run</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.sh</include>
                <include>*.bat</include>
            </includes>
        </fileSet>

    </fileSets>

    <dependencySets>
        <!-- 将scope为runtime的依赖包打包到lib目录下。 -->
        <dependencySet>
            <useProjectArtifact>true</useProjectArtifact>
            <outputDirectory>libs</outputDirectory>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>

</assembly>

3.增加startup.bat

@echo off
setLocal enableDelayedExpansion
set cp=.
FOR %%i IN ("%~dp0libs\*.jar") DO set cp=!cp!;%%~fsi
start "quotation_front" java -server -cp %cp% Shell

4.增加startup.sh (com.lagou.ProviderApplication这个为main方法的全路径)

#!/bin/sh
baseDir=$(cd "$(dirname "$0")"; pwd)
cp=.
for file in $baseDir/libs/*.jar
do
   cp=$cp:$file
done
java -server -Xmx2048m -Xss256k -cp $cp  com.lagou.ProviderApplication >> $baseDir/stdout.out 2>&1 &

最后执行maven打包install,找到打包后文件解压上传到linux服务器直接执行startup.sh就可以了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值