簡體   English   中英

如何從 Maven 依賴項中獲取 class 文件到 target\classes 文件夾

[英]How can I get class files from Maven dependency into the target\classes folder

是否有任何類型的 Maven 插件允許我將依賴項的 class 文件復制到我的項目的 target\classes 文件夾中? 目前,我必須手動打開具有依賴項的 jar 文件提取我需要復制的 package,然后將其復制到我的項目的 target\class 文件夾中。

我需要一種在 pom.xml 文件中理想地完成這些工作的方法,但我無法找到有效的解決方案。 任何幫助將不勝感激,謝謝。

使用 maven-dependency-plugin。 以下是如何提取依賴項 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>

這聽起來是個可怕的主意。 如果您想在項目中包含解壓的依賴項,請使用 maven 程序集插件或 maven 陰影插件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM