maven打包jar

在用到maven管理的工程,想输出jar包就不能用eclipse outport这种方式,需要用命令行maven来输出,步骤如下

1.下载maven-assembly-plugin插件

2.在pom.xml中插入

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <!-- 应用名(最后压缩包的名字) -->
                <finalName>buy</finalName>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptors>
                    <descriptor>assembly.xml</descriptor>
                </descriptors>
            </configuration>
        </plugin>
     <plugins>
</build>

3.在根目录下新建assembly.xml文件,并插入如下内容:

<?xml version="1.0" encoding="GBK"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
 
    <id>tgz</id>
    <!-- 应用名-run(压缩包解压后的目录名) -->
    <baseDirectory>buy</baseDirectory>
    <formats>
        <!-- 压缩包的格式,一律为tar.gz -->
        <format>tar.gz</format>
    </formats>
 
    <fileSets>
        <fileSet>
            <!-- 应用jar生成的目录 -->
            <directory>${project.build.directory}</directory>
            <!-- 输出的目录,此处为空即可 -->
            <outputDirectory></outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
                <fileSet>
            <!-- 应用自定义的appctl.sh所在的bin目录 -->
            <directory>bin</directory>
            <!-- 输出的目录到应用名下的bin 目录 -->
            <outputDirectory>/bin</outputDirectory>
            <includes>
                <include>**/**</include>
            </includes>
        </fileSet>
    </fileSets>
    <dependencySets>
        <dependencySet>
            <useProjectArtifact>true</useProjectArtifact>
            <!-- 运行时依赖统一放在lib目录下 -->
            <outputDirectory>lib</outputDirectory>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
</assembly>

4. 在根目录下 mvn -U -Dmaven.test.skip=true clean package assembly:assembly,在target目录下生成名为 finalName.tar.gz的压缩包







你可能感兴趣的:(eclipse,maven,jar,压缩包)