zoukankan      html  css  js  c++  java
  • 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  ## 执行文件复制成功。
    

      

      

  • 相关阅读:
    Service(服务)简单使用
    Android设计模式——抽象工厂方法模式
    Android设计模式——工厂方法模式
    算法问题——递归算法
    Android设计模式——Builder(建造者)模式
    Android设计模式——单例模式
    蓝牙4.0权限问题
    Android 网络状态变化的监听
    RecyclerView的使用
    函数参数的引用传递与值传递
  • 原文地址:https://www.cnblogs.com/xhzd/p/11926379.html
Copyright © 2011-2022 走看看