Maven WAR Overlays - 包括解压缩的依赖项

And*_*ers 2 coldfusion maven-2 maven

我正在尝试使用Maven设置一个项目,并且我对如何在生成的war文件中包含一些需要解包的第三方依赖项感到困惑.

我的项目包含一些自定义的ColdFusion代码,并包含Java依赖项,包括打包为war文件的ColdFusion.然后我试图包含一些第三方ColdFusion代码,我已经将其安装在我的maven资源库中打包为jar,但实际上我想在生成的war文件中将其解压缩.这就是我对第三方图书馆的解压缩.我真的希望在战争结束之前完成这项任务,以便我可以使用战争:在开发过程中爆炸.

目前我的pom.xml看起来像这样:

    <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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.mycompany.app</groupId>
      <artifactId>my-webapp</artifactId>
      <packaging>war</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>my-webapp Maven Webapp</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>

        <!-- This is the war overlay -->
        <dependency>
            <groupId>com.adobe.coldfusion</groupId>
            <artifactId>coldfusion</artifactId>
            <version>9.0.1</version>
            <type>war</type>
            <scope>runtime</scope>
            <optional>false</optional>
        </dependency>  

        <!-- This is the 3rd party ColdFusion dependency -->    
        <dependency>
            <groupId>org.corfield</groupId>
            <artifactId>fw1</artifactId>
            <version>1.2RC2A</version>
            <scope>provided</scope>
        </dependency>

     </dependencies>
     <build>
        <finalName>my-webapp</finalName>
     </build>
  </project>
Run Code Online (Sandbox Code Playgroud)

通过修改构建部分,我有点做了我想要的事情,如下所示:

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>package</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.corfield</groupId>
                                <artifactId>fw1</artifactId>
                                <version>1.2RC2A</version>
                                <type>jar</type>
                                <overWrite>true</overWrite>
                                <outputDirectory>${project.build.directory}/${project.artifactId}</outputDirectory>
                                <includes>**/*.cfc</includes>
                            </artifactItem>
                           </artifactItems>
                        <includes>**/*.cfc</includes>
                        <outputDirectory>${project.build.directory}/${project.artifactId}</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>

                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

这个问题是在构建war之后发生了package:unpack,因此解压缩的dependecies不在生成的war文件中.

我还尝试了一下使用程序集插件的一些东西,我也很接近使用这样的东西:

<assembly>
    <id>${project.artifactId}</id>
    <formats>
        <format>war</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <includes>
                <include>org.corfield:fw1</include>
            </includes>
            <unpack>true</unpack>
            <outputDirectory>/</outputDirectory>
        </dependencySet>
        <dependencySet>
            <excludes>
                <exclude>org.corfield:fw1</exclude>
            </excludes>
            <unpack>false</unpack>
            <outputDirectory>/WEB-INF/lib</outputDirectory>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <directory>src/main/webapp</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>
Run Code Online (Sandbox Code Playgroud)

然而,这创建了第二个war文件,名为my-webapp-1.0-SNAPSHOT-my-webapp.war以及my-webapp-1.0-SNAPSHOT.war.my-webapp-1.0-SNAPSHOT-my-webapp.war还包括my-webapp-1.0-SNAPSHOT.war

在一天结束时,我希望我的战争结果如下:

org
 |-- corfield
    |-- framework.cfc
WEB-INF
 |-- lib
 |-- web.xml
index.cfm
Run Code Online (Sandbox Code Playgroud)

(实际上它还有很多东西,但这足以说明这一点有希望)

我觉得我很接近,但我只是缺少一些我需要的东西.我非常感谢任何帮助.

Pas*_*ent 5

对于该maven-dependency-plugin方法,将阶段(Maven 2.1+)unpack上的目标绑定prepare-package而不是package.

参考