如何将类文件从Maven依赖项放入目标\Clages文件夹

ehxuflar  于 2022-10-26  发布在  Maven
关注(0)|答案(3)|浏览(172)

是否有任何类型的Maven插件允许我将依赖项的类文件复制到我的项目的Target\Classes文件夹中?目前,我必须手动打开包含依赖项的JAR文件,提取需要复制的包,然后将其复制到项目的目标\class文件夹中。
理想情况下,我需要一种在pom.xml文件中完成这些操作的方法,但我还没有找到一种可行的解决方案。任何帮助都将不胜感激,谢谢。

zqry0prt

zqry0prt1#

这听起来是个糟糕的主意。如果要在项目中包含未打包的依赖项,请使用maven汇编插件或maven shape插件。

iovurdzv

iovurdzv2#

使用maven-Dependency-plugin。Here is an example介绍如何提取依赖项JAR的内容:

<project>
       [...]
       <build>
         <plugins>
           <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-dependency-plugin</artifactId>
             <version>3.1.2</version>
             <executions>
               <execution>
                 <id>unpack</id>
                 <phase>package</phase>
                 <goals>
                   <goal>unpack</goal>
                 </goals>
                 <configuration>
                   <artifactItems>
                     <artifactItem>
                       <groupId>junit</groupId>
                       <artifactId>junit</artifactId>
                       <version>3.8.1</version>
                       <type>jar</type>
                       <overWrite>false</overWrite>
                       <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                       <destFileName>optional-new-name.jar</destFileName>
                       <includes>**/*.class,**/*.xml</includes>
                       <excludes>**/*test.class</excludes>
                     </artifactItem>
                   </artifactItems>
                   <includes>**/*.java</includes>
                   <excludes>**/*.properties</excludes>
                   <outputDirectory>${project.build.directory}/wars</outputDirectory>
                   <overWriteReleases>false</overWriteReleases>
                   <overWriteSnapshots>true</overWriteSnapshots>
                 </configuration>
               </execution>
             </executions>
           </plugin>
         </plugins>
       </build>
       [...]
     </project>
dfddblmv

dfddblmv3#

下面是使用汇编语言的例子,它对我很有效

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.4.2</version>
    <configuration>
        <archive>
            <manifest>
                <mainClass>my parent package statup class</mainClass>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

相关问题