本文主要展示了“maven如何打包zip以包含bin下的启动脚本”。内容简单易懂,条理清晰。希望能帮你解开疑惑。让边肖带领你学习这篇文章“maven如何打包zip以包含bin下的启动脚本”。
Maven package zip包含bin下的启动脚本,该脚本在idea上进行了有效的编辑和测试:
Package pom.xml
建设
sourceDirectorysrc/main/Scala/source directory
testSourceDirectorysrc/test/Scala/testSourceDirectory
资源
资源
目录RC/主/资源/目录
包含
包括**/*。属性/包括
包括**/*。xml/include
/包括
!-排除外部配置文件(在运行时注释上,以便IDE可以读取配置文件;打包时,放开注释,让配置文件对外,方便修改。)你可以不配置它,但是它已经在maven-jar-plugin-下面配置好了
!-不包括
excludeconfig.properties/exclude
/不包括-
/资源
!-配置文件外部的资源(存储在conf目录中,该目录也是类路径,将在下面配置)
!-资源
nbsp; <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下启动脚本”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/59856.html