文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

maven如何打包zip包含bin下启动脚本

2023-06-25 11:52

关注

这篇文章主要为大家展示了“maven如何打包zip包含bin下启动脚本”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“maven如何打包zip包含bin下启动脚本”这篇文章吧。

maven打包zip包含bin下启动脚本,这个脚本小编在idea上测试有效:

pom.xml打包

<build>        <sourceDirectory>src/main/scala</sourceDirectory>        <testSourceDirectory>src/test/scala</testSourceDirectory>        <resources>            <resource>                <directory>src/main/resources</directory>                <includes>                    <include>***.xml</include>                </includes>                <!-- 排除外置的配置文件(运行时注释上,使IDE能读到配置文件;打包时放开注释让配置文件外置,方便修改)可以不配置,maven-jar-plugin下面已配置 -->                <!--<excludes>                    <exclude>config.properties</exclude>                </excludes>-->            </resource>            <!-- 配置文件外置的资源(存放到conf目录,也是classpath路径,下面会配置)-->            <!--<resource>                <directory>src/main/resources</directory>                <includes>                    <include>config.properties</include>                </includes>                <targetPath>${project.build.directory}/conf</targetPath>            </resource>-->        </resources>        <plugins>            <!--scala编译打包插件-->            <plugin>                <groupId>net.alchim31.maven</groupId>                <artifactId>scala-maven-plugin</artifactId>                <version>3.2.1</version>                <executions>                    <execution>                        <id>scala-compile-first</id>                        <phase>process-resources</phase>                        <goals>                            <goal>add-source</goal>                            <goal>compile</goal>                        </goals>                    </execution>                </executions>            </plugin>            <!--java编译打包插件-->            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-compiler-plugin</artifactId>                <version>3.1</version>                <configuration>                    <source>1.8</source>                    <target>1.8</target>                    <encoding>UTF-8</encoding>                </configuration>                <executions>                    <execution>                        <phase>compile</phase>                        <goals>                            <goal>compile</goal>                        </goals>                    </execution>                </executions>            </plugin>            <!--                ③打成一个zip包,发布项目的时候,将zip包copy到服务器上,直接unzip xxx.zip,里面包含要运行到的jar以及依赖的lib,还有配置的config文件,即可直接启动服务            -->            <!--The configuration of maven-jar-plugin-->            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-jar-plugin</artifactId>                <version>2.4</version>                <!--The configuration of the plugin-->                <configuration>                    <!-- 不打包资源文件(配置文件和依赖包分开) -->                    <excludes>                        <exclude>*.properties</exclude>                        <exclude>*.xml</exclude>                        <exclude>*.txt</exclude>                    </excludes>                    <!--Configuration of the archiver-->                    <archive>                        <!--生成的jar中,不要包含pom.xml和pom.properties这两个文件-->                        <addMavenDescriptor>false</addMavenDescriptor>                        <!--Manifest specific configuration-->                        <manifest>                            <!--是否把第三方jar放到manifest的classpath中-->                            <addClasspath>true</addClasspath>                            <!--生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/-->                            <classpathPrefix>lib/</classpathPrefix>                            <!--应用的main class-->                            <mainClass>com.swordfall.restserver.base.WebServer</mainClass>                        </manifest>                        <!-- 给清单文件添加键值对,增加classpath路径,这里将conf目录也设置为classpath路径 -->                        <manifestEntries>                            <Class-Path>conf/</Class-Path>                        </manifestEntries>                    </archive>                    <!--过滤掉不希望包含在jar中的文件-->                    <!-- <excludes>                         <exclude>${project.basedir}/xml/*</exclude>                     </excludes>-->                </configuration>            </plugin>            <!--The configuration of maven-assembly-plugin-->            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-assembly-plugin</artifactId>                <version>2.4</version>                <!--The configuration of the plugin-->                <configuration>                    <!--Specifies the configuration file of the assembly plugin-->                    <descriptors>                        <descriptor>src/main/assembly/assembly.xml</descriptor>                    </descriptors>                </configuration>                <executions>                    <execution>                        <id>make-assembly</id>                        <phase>package</phase>                        <goals>                            <goal>single</goal>                        </goals>                    </execution>                </executions>            </plugin>        </plugins>    </build>

 assembly.xml打包zip设置

assembly.xml<assembly>    <id>bin</id>    <includeBaseDirectory>false</includeBaseDirectory>    <!-- 最终打包成一个用于发布的zip文件 -->    <formats>        <format>zip</format>    </formats>    <!-- Adds dependencies to zip package under lib directory -->    <dependencySets>        <dependencySet>            <!-- 不使用项目的artifact,第三方jar不要解压,打包进zip文件的lib目录 -->            <useProjectArtifact>false</useProjectArtifact>            <outputDirectory>lib</outputDirectory>            <unpack>false</unpack>        </dependencySet>    </dependencySets>    <fileSets>        <!-- 把项目相关的说明文件,打包进zip文件的根目录 -->        <!--<fileSet>            <directory>${project.basedir}</directory>            <outputDirectory>/</outputDirectory>        </fileSet>-->        <!-- 把项目的配置文件,打包进zip文件的config目录 -->        <!--<fileSet>-->        <!--<directory>${project.basedir}/src/main/resources</directory>-->        <!--<outputDirectory>/conf</outputDirectory>-->        <!--<includes>-->        <!--<include>*.xml</include>-->        <!--<include>*.properties</include>-->        <!--</includes>-->        <!--</fileSet>-->        <!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 -->        <fileSet>            <directory>${project.build.directory}</directory>            <outputDirectory></outputDirectory>            <includes>                <include>*.jar</include>            </includes>        </fileSet>        <!-- 把项目的脚本文件目录(src/main/scripts)中的启动脚本,打包进zip文件的根目录 -->        <fileSet>            <directory>${project.basedir}/src/main/bin</directory>            <outputDirectory>bin</outputDirectory>            <includes>                <include>*.sh</include>            </includes>        </fileSet>    </fileSets></assembly>

ps:下面看下maven 打zip包并包含bin和docs文件夹

maven插件:

<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration>  <appendAssemblyId>false</appendAssemblyId>  <descriptors>   <descriptor>src/main/resources/assembly.xml</descriptor>  </descriptors> </configuration> <executions>  <execution>   <id>make-assembly</id>   <phase>package</phase>   <goals>    <goal>single</goal>   </goals>  </execution> </executions></plugin>

assembly.xml

<assembly>    <id>package</id>    <formats>        <format>zip</format>    </formats>    <includeBaseDirectory>false</includeBaseDirectory>    <fileSets>        <fileSet>            <directory>${project.parent.basedir}/bin</directory>            <outputDirectory>\bin</outputDirectory>        </fileSet>        <fileSet>            <directory>${project.parent.basedir}/db</directory>            <outputDirectory>\db</outputDirectory>        </fileSet>        <fileSet>            <directory>${project.parent.basedir}/docs</directory>            <outputDirectory>\docs</outputDirectory>        </fileSet>        <fileSet>            <directory>${project.parent.basedir}</directory>            <outputDirectory>\</outputDirectory>            <includes>                <include>readme.md</include>                <include>release-notes</include>            </includes>        </fileSet>        <fileSet>            <directory>${project.build.directory}</directory>            <outputDirectory>\</outputDirectory>            <includes>                <include>*.jar</include>            </includes>        </fileSet>    </fileSets></assembly>

以上是“maven如何打包zip包含bin下启动脚本”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网行业资讯频道!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯