简体   繁体   English

如何使用Maven合并本地jar

[英]How to merge local jars using maven

I have a requirement to merge some jar into a common jar using maven. 我需要使用Maven将一些jar合并到一个普通的jar中。 My system looks like as follows 我的系统如下

first 
    |_ out 
        |-- jar1.jar
        |-- jar2.jar

second
    |--out
        |-- jar3.jar
        |-- jar4.jar

I wants to merge those 4 jar into one jar and place them in 我想将这四个罐子合并成一个罐子,然后放入

first 
    |-- out
            |-- msg

I tried to use maven-shade plugin but I am not sure how to provide the path to those jar 我尝试使用maven-shade插件,但不确定如何提供这些jar的路径

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <minimizeJar>true</minimizeJar>
              <filters>
                <filter>
                   <artifact>jar1:jar1</artifact>
                   <includes>
                       <include>**</include>
                   </includes>
                </filter>
                <filter>
                   <artifact>jar2:jar2</artifact>
                   <includes>
                       <include>**</include>
                   </includes>
                </filter>
                <filter>
                   <artifact>jar4:jar4</artifact>
                   <includes>
                       <include>**</include>
                   </includes>
                </filter>
                <filter>
                   <artifact>jar3:jar3</artifact>
                   <includes>
                       <include>**</include>
                   </includes>
                </filter>
              </filters>            
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

If there is any other way I am open for that. 如果还有其他方法,我愿意这样做。

You can't put jar files into another jar file, -jar files don't work that way. 您不能将jar文件放到另一个jar文件中,-jar文件不能那样工作。 What you need is for all of the contents of all of the jar files to be extracted, and then zipped up again into one jar. 您需要提取所有jar文件的所有内容,然后再次将其压缩到一个jar中。

Edit : 编辑
<include> : instruct it what dependencies to pull into the uber JAR <include> :指示它将哪些依赖项放入uber JAR

<include>groupId:artifactId</include>

<excludes> : excludes some stuff from the target JAR that shouldn't be in there - such as JAR metadata, ant build files, text files, etc <excludes> :从目标JAR中排除不应包含的某些内容,例如JAR元数据,ant构建文件,文本文件等

something like this 像这样的东西

 <configuration>
    <minimizeJar>true</minimizeJar>
      <artifactSet>
         <includes>
            <include>com.google.guava:guava</include>
            <include>net.sf.trove4j:trove4j</include>
            <include>org.mvel:mvel2</include>
            <include>com.fasterxml.jackson.core:jackson-core</include>
            <include>joda-time:joda-time</include>
          </includes>
        </artifactSet>
        <filters>
           <filter>
              <artifact>*:*</artifact>
                <excludes>
                    <exclude>META-INF/license/**</exclude>
                    <exclude>META-INF/*</exclude>
                    <exclude>META-INF/maven/**</exclude>
                    <exclude>LICENSE</exclude>
                    <exclude>NOTICE</exclude>
                    <exclude>/*.txt</exclude>
                    <exclude>build.properties</exclude>
                </excludes>
            </filter>
        </filters>
 </configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM