I maven-assembly-plugin maven jar 打包依赖为一个包



一、测试新项目
public class EncodeTest {
public static void main(String[] args) {
System.out.println("sun.jnu.encoding >>>" + System.getProperty("sun.jnu.encoding"));
System.out.println("file.encoding >>>" + System.getProperty("file.encoding"));

try {
FileUtils.copyFile(new File("/var/aiplatform/test/1.jpg"),new File("/var/aiplatform/test/张小泉呵呵_111_zxq.com.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}
}

如下pom.xml 可以将 commons-io打到同一个jar包中。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xx.test</groupId>
    <artifactId>testfile</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
    </dependencies>

    <build>
      <finalName>testfile</finalName>
        <plugins>
            <!-- maven-assembly-plugin -->
            <!-- 打包方式:mvn package assembly:single  -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.5</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.xx.test.EncodeTest</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>assembly</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
maven package  # 打包成功

 java -jar testfile-jar-with-dependencies.jar  ## 执行文件复制成功。

  

 

  

posted @ 2019-11-25 10:44  星回中道  阅读(482)  评论(0编辑  收藏  举报