Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将Maven依赖项解包到类中,保留可传递的依赖项_Java_Maven_Jar_Dependencies_Pom.xml - Fatal编程技术网

Java 将Maven依赖项解包到类中,保留可传递的依赖项

Java 将Maven依赖项解包到类中,保留可传递的依赖项,java,maven,jar,dependencies,pom.xml,Java,Maven,Jar,Dependencies,Pom.xml,我试图将maven依赖项jar的内容解压到我的classes文件夹中,同时包含可传递的依赖项。我也不想解包我的项目的所有依赖项。只有一个是好的,如果我可以这样做的名单。找到了类似的解决方案,但没有解决我的确切问题 主要项目Pom示例: . . . <dependencies> <dependency> <groupId>com.test.dep</groupId> <artifact>first-dependency

我试图将maven依赖项jar的内容解压到我的classes文件夹中,同时包含可传递的依赖项。我也不想解包我的项目的所有依赖项。只有一个是好的,如果我可以这样做的名单。找到了类似的解决方案,但没有解决我的确切问题

主要项目Pom示例:

.
.
.
<dependencies>
  <dependency>
    <groupId>com.test.dep</groupId>
    <artifact>first-dependency</artifact>
  </dependency>
  <dependency>
    <groupId>com.test.dep</groupId>
    <artifact>second-dependency</artifact>
  </dependency>
</dependencies>
.
.
.
这在我的classes文件夹中包含了第二个依赖项的内容,但在我的主projects lib目录中没有包含第三个依赖项或第四个依赖项


有什么想法吗?

根据所述的参数,尝试使用以下插件配置:

org.apache.maven.plugins . 这个插件能够将项目本身的类和资源以及一组指定的工件依赖项打包到一个jar中

只需定义工件本身${project.groupId}:${project.artifactId}和要包含的第二个依赖项

org.apache.maven.plugins maven阴影插件 2.1 ${project.groupId}:${project.artifactId} dep:第二个依赖项 包裹 阴凉处
这种方法奏效了。但我真正想做的是在second dependencies的pom中包含所有依赖项,将second dependency解压到我的classes文件夹中,同时在我的lib文件夹中不包含second-dependency.jar。
.
.
.
<dependencies>
  <dependency>
    <groupId>com.test.dep</groupId>
    <artifact>third-dependency</artifact>
  </dependency>
  <dependency>
    <groupId>com.test.dep</groupId>
    <artifact>fourth-dependency</artifact>
  </dependency>
</dependencies>
.
.
.
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>com.test.dep</groupId>
                        <artifactId>second-dependency</artifactId>
                        <type>jar</type>
                        <overWrite>true</overWrite>
                        <outputDirectory>${project.build.directory}/classes</outputDirectory>
                        <includes>**/*</includes>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>