maven打包zip包含bin下启动脚本的完整代码
更新时间:2021年10月28日 00:00 点击:1777 作者:架构艺术
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>**/*.properties</include> <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下启动脚本的文章就介绍到这了,更多相关maven打包zip内容请搜索猪先飞以前的文章或继续浏览下面的相关文章希望大家以后多多支持猪先飞!
原文出处:https://www.cnblogs.com/LIAOBO/p/15471400.html
相关文章
解决执行maven命令时提示Process terminated的问题
这篇文章主要介绍了解决执行maven命令时提示Process terminated的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-09-25- 这篇文章主要介绍了详解如何将c语言文件打包成exe可执行程序,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-25
- 这篇文章主要介绍了解决idea2020 maven无法自动导包的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-13
解决IDEA maven 项目修改代码不生效,mvn clean、install后才生效
这篇文章主要介绍了解决IDEA maven 项目修改代码不生效,mvn clean、install后才生效的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-09-25- 这篇文章主要介绍了idea 打包maven项目忽略test文件的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-05
详解Maven profile配置管理及激活profile的几种方式
这篇文章主要介绍了详解Maven profile配置管理及激活profile的几种方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-26将c#编写的程序打包成应用程序的实现步骤分享(安装,卸载) 图文
时常会写用c#一些程序,但如何将他们和photoshop一样的大型软件打成一个压缩包,以便于发布....2020-06-25- 这篇文章主要介绍了Pyinstaller打包文件太大的解决方案,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-09
- 这篇文章主要介绍了详解idea从git上拉取maven项目详细步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-08-12
使用Maven 搭建 Spring MVC 本地部署Tomcat的详细教程
这篇文章主要介绍了使用Maven 搭建 Spring MVC 本地部署Tomcat,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-08-16- 这篇文章主要介绍了python打包生成so文件的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-10-30
- 这篇文章主要介绍了Maven打包的相关知识,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-09-13
- 这篇文章主要介绍了idea+maven打jar包的两种方式,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-07-16
- 这篇文章主要介绍了vue cli3 实现分环境打包的步骤,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-03-12
idea2020.3配置maven环境并配置Tomcat的详细教程
这篇文章主要介绍了idea2020.3配置maven环境并配置Tomcat的详细教程,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-03-19- 这篇文章主要介绍了使用maven的profile构建不同环境配置的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-26
- 这篇文章主要介绍了编译打包video.js的方法,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧...2020-12-09
- 本文主要介绍了Vue打包后页面出现空白解决办法,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-08-03
- 本文主要介绍了webpack搭建脚手架打包TypeScript代码,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-21
JavaScript 实现的 zip 压缩和解压缩工具包Zip.js使用详解
今天给大家介绍的文章是js实现的解压缩插件zip.js,非常的简单实用,有需要的小伙伴可以参考下。...2015-12-16