Maven导出jar包

1.mvn clean package
导出jar包,项目依赖的jar包会导出到/target/lib/目录下

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-jar-plugin</artifactId>  
    <version>2.4</version>  
    <configuration>  
        <archive>  
            <manifest>  
                <addClasspath>true</addClasspath>  
                <classpathPrefix>lib/</classpathPrefix>  
                <mainClass>com.sysware.HelloWorld</mainClass>  
            </manifest>  
        </archive>  
    </configuration>  
</plugin>  

2.mvn assembly:assembly
若项目依赖别的lib库,assembly会把所有的jar包导出成一个可执行jar包。

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-assembly-plugin</artifactId>  
    <version>2.3</version>  
    <configuration>  
        <appendAssemblyId>false</appendAssemblyId>  
        <descriptorRefs>  
            <descriptorRef>jar-with-dependencies</descriptorRef>  
        </descriptorRefs>  
        <archive>  
            <manifest>  
                <mainClass>com.juvenxu.mvnbook.helloworld.HelloWorld</mainClass>  
            </manifest>  
        </archive>  
    </configuration>  
    <executions>  
        <execution>  
            <id>make-assembly</id>  
            <phase>package</phase>  
            <goals>  
                <goal>assembly</goal>  
            </goals>  
        </execution>  
    </executions>  
</plugin>

3.

<build>  
    <finalName>...</finalName>  
    <sourceDirectory>src/main/java</sourceDirectory>  
    <resources>  
        <!-- 控制资源文件的拷贝 -->  
        <resource>  
            <directory>src/main/resources</directory>  
            <targetPath>${project.build.directory}</targetPath>  
        </resource>  
    </resources>  
    <plugins>  
        <!-- 设置源文件编码方式 -->  
        <plugin>  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-compiler-plugin</artifactId>  
            <configuration>  
                <defaultLibBundleDir>lib</defaultLibBundleDir>  
                <source>1.6</source>  
                <target>1.6</target>  
                <encoding>UTF-8</encoding>  
            </configuration>  
        </plugin>  
        <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->  
        <plugin>  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-jar-plugin</artifactId>  
            <configuration>  
                <archive>  
                    <manifest>  
                        <addClasspath>true</addClasspath>  
                        <classpathPrefix>lib/</classpathPrefix>  
                        <mainClass>.....MonitorMain</mainClass>  
                    </manifest>  
                </archive>  
            </configuration>  
        </plugin>  
        <!-- 拷贝依赖的jar包到lib目录 -->  
        <plugin>  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-dependency-plugin</artifactId>  
            <executions>  
                <execution>  
                    <id>copy</id>  
                    <phase>package</phase>  
                    <goals>  
                        <goal>copy-dependencies</goal>  
                    </goals>  
                    <configuration>  
                        <outputDirectory>  
                            ${project.build.directory}/lib  
                        </outputDirectory>  
                    </configuration>  
                </execution>  
            </executions>  
        </plugin>  
        <!-- 解决资源文件的编码问题 -->  
        <plugin>  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-resources-plugin</artifactId>  
            <version>2.3</version>  
            <configuration>  
                <encoding>UTF-8</encoding>  
            </configuration>  
        </plugin>  
        <!-- 打包source文件为jar文件 -->  
        <plugin>  
            <artifactId>maven-source-plugin</artifactId>  
            <version>2.1</version>  
            <configuration>  
                <attach>true</attach>  
                <encoding>UTF-8</encoding>  
            </configuration>  
            <executions>  
                <execution>  
                    <phase>compile</phase>  
                    <goals>  
                        <goal>jar</goal>  
                    </goals>  
                </execution>  
            </executions>  
        </plugin>  
    </plugins>  
</build>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值