【问题标题】:How to move (or copy) a war's jar to another war's folder?如何将战争的 jar 移动(或复制)到另一个战争的文件夹?
【发布时间】:2014-10-21 19:27:54
【问题描述】:

我有 maven prj 和 2 个模块:一个 JAR 和一个依赖于 JAR 的 WAR。

在 MAVEN INSTALL 之后,我将包含所有 jar 依赖项(包括第一个模块的 JAR)的经典 WEB-INF/lib 文件夹放入 WAR 中。

我需要将第一个模块的 JAR 移动到另一个文件夹,例如 WEB-INF/resources。 如我所能?

我能够移动罐子,但只能在目标内移动,WAR 保持不变。 我使用了以下插件:

...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.9</version>
            <executions>
                <execution>
                    <id>copy-installed</id>
                    <phase>install</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>groupId</groupId>
                                <artifactId>artifactId</artifactId>
                                <version>1.0</version>
                                <type>jar</type>
                                <overWrite>false</overWrite>
                                <outputDirectory>${project.build.directory}/.../WEB-INF/services</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                        <outputDirectory>${project.build.directory}/.../WEB-INF/services</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>    

【问题讨论】:

  • 我认为您必须为此创建新模块,并且在执行 mvn-clean 安装时,您可以将任何文件移动到任何目录。

标签: java maven jar war maven-plugin


【解决方案1】:

现在,我投降了。

我无法将此 JAR 从 WEB-INF/lib 移动到 EAR 的 WEB-INF/services。 我使用的解决方法是说 MODULE1 将其 JAR 复制到 MODULE2 的 WEB-INF/services 中。因此,JAR 将出现在源文件夹的 WEB-INF/services 中,在 TARGET 文件夹的 WEB-INF/services 中,最后在 EAR 的 WEB-INF/services 中。

我用过:

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <outputDirectory>..MOSULE1/src/main/webbapp/WEB-INF/services</outputDirectory>
            </configuration>
        </plugin>
    </plugins>

进入 MODULE1 pom。

我不得不放弃让module1独立于module2 ;(

我希望我能找到一个干净的解决方案..

【讨论】:

    【解决方案2】:

    也许这会有所帮助:

    <project.warSourceDirectory>${basedir}/src/main/webapp</project.warSourceDirectory>
    ...
    
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.9</version>
        <executions>
            <execution>
                <id>copy-installed</id>
                <phase>install</phase>
                <goals>
                    <goal>copy</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>groupId</groupId>
                            <artifactId>artifactId</artifactId>
                            <version>1.0</version>
                            <type>jar</type>
                            <overWrite>false</overWrite>
                            <outputDirectory>${project.warSourceDirectory}/WEB-INF/services</outputDirectory>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

    • 感谢您的回答。 ${project.warSourceDirectory} 对我不起作用,它会在主 prj dir 中生成一个名为 ${project.warSourceDirectory} 的文件夹:D
    • 没什么,我用这个 ${project.build.directory} 代替那个 ${project.warSourceDirectory},insall 在 TARGET 下生成一个 WEB-INF/services 过滤器,在大坝内部JAR,(这不是必需的,而是正确的)。但是 WAR 创建不包含它。我认为PLUGIN在安装后工作,它在WAR生成后移动JAR,我不知道如何告诉他之前这样做。复制应该发生在 JAR 的生成(安装模块 1)和 WAR 的生成(安装模块 2)之间。
    • @pagurix 我们将它与 prepare-package 一起使用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 2018-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多