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>**/*.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内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • maven插件assembly使用及springboot启动脚本start.sh和停止脚本 stop.sh

    我们在项目中都会遇到项目打包,可以通过assembly对我们的项目进行打包. 1.首先看一下在打包前的项目文件结构. 2.在pom.xml中配置assembly插件 <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plug

  • java application maven项目打自定义zip包实例(推荐)

    1.配置pom.xml文件,添加build节点 <build> <!-- 输出的包名 --> <finalName>p2p</finalName> <sourceDirectory>src/main/java</sourceDirectory> <resources> <!-- 控制资源文件的拷贝(默认复制到classes目录,最后打进jar包) --> <resource> <directo

  • 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

  • 使用Maven打包时包含资源文件和源码到jar的方法

    目录 Maven打包时包含资源文件和源码到jar 在<build>中添加以下内容 意义如下 maven打包时包含源码的问题 Maven打包时包含资源文件和源码到jar 在使用Maven打包时,我们发现最终打包之后jar中只有已经编译完成的代码class,资源文件都没了,如果有资源文件需要打包进jar的话,直接打包jar无法正常工作. 其实,在pom.xml中配置一下<build>节点即可实现把资源打包进来的操作. 在<build>中添加以下内容 <resource

  • js+div+css下拉导航菜单完整代码分享

    效果预览:http://keleyi.com/keleyi/phtml/menu/1.htm 下拉菜单 js+div+css下拉导航菜单完整代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w

  • Java的后台文件夹下文件的遍历完整代码

    一.在java中遍历一个文件夹里边的所有文件,可以有两种方式: 1.递归遍历,通常也是开发者第一时间能想到的方法,递归遍历的优点是:实现起来相对简单,代码量相对较少,执行效率较高,缺点是:比较吃内存,对硬件要求较高 // 递归遍历 private void getDirectory(File file) { File flist[] = file.listFiles(); if (flist == null || flist.length == 0) { return 0; } for (Fil

  • Maven打包并生成运行脚本的示例代码

    1.定义插件 <properties> <maven-jar-plugin.version>2.4</maven-jar-plugin.version> <maven-assembly-plugin.version>2.4</maven-assembly-plugin.version> <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>

  • Springboot jar文件如何打包zip在linux环境运行

    这篇文章主要介绍了Springboot jar文件如何打包zip在linux环境运行,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1.添加打包配置文件 1.1 assembly.xml <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2

  • springboot启动脚本start.sh和停止脚本 stop.sh的详细教程

    我们在项目中都会遇到项目打包,可以通过assembly对我们的项目进行打包. 针对打包构建jar包,本文不再叙述.具体可以参考maven插件assembly使用及springboot启动脚本start.sh和停止脚本 stop.sh 这里面已经有一个springboot 的启动脚本了,本文之所以还要写,是因为之前的脚本存在一个问题.关闭脚本的时候是通过kill -9 命令进行的,但其实我们项目中可能很多时候不能强制关闭的,在关闭之前需要做一些事情.比如将内存数据存到磁盘,dubbo清空zooke

  • 非常实用的Tomcat启动脚本实现方法

    前言 有这样一个场景,公司为了安全起见,需要对所有登录Linux服务器做安全限制,要求除了管理员其他要登录linux服务器的员工不能用最高权限账号登录,要创建新的用户,对目录及文件权限做出控制,只能对需要操作的目录允许读,写,执行权限,其他目录只有读的权限,并且所有tomcat不能直接在bin中用startup.sh,shutdown.sh进行启动和停止,要通过写shell脚本进行此操作,也就是说有两个步骤,创建用户并设置权限,写tomcat启动脚本,下面我们就完成这两个步骤. 1.首先我们就来

  • Linux下启动多个mysql服务器例子

    1.  创建多个mysql database目录 复制代码 代码如下: Mysql_install_db  --datadir=/data/mysql_3307 2.  设置database目录权限 复制代码 代码如下: Chown –R mysql /data 3.  拷贝.设置my.cnf 复制代码 代码如下: cp  XXX/my.cnf /data/mysql_3307/my.cnf 添加my.cnf 复制代码 代码如下: log-error = /data/mysql_3307/loc

随机推荐