【问题标题】:Unpack an EAR file using maven使用 maven 解压 EAR 文件
【发布时间】:2013-03-05 23:50:40
【问题描述】:

我有一个来自某个构建的 EAR 文件。我想将此 EAR 文件的内容提取到另一个文件夹中。我很困惑如何做到这一点。我已经看过并尝试过 http://maven.apache.org/plugins/maven-ear-plugin/http://maven.apache.org/plugins/maven-dependency-plugin/usage.html

但是 maven 无法找到该文件或存在依赖问题。

由于我是 maven 新手,我不明白如何设置这些插件。

使用以下插件时出现以下错误。

http://repo.maven.apache.org/maven2 中找不到 ECM:ECM:ear:1.0 失败已缓存在本地存储库中

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>package</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>ECM</groupId>
                                <artifactId>ECM</artifactId>
                                <version>1.0</version>
                                <type>ear</type>
                            </artifactItem>
                        </artifactItems>
                        <outputDirectory>${project.build.directory}/earoutput</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

【问题讨论】:

  • 我厌倦了 maven 中的 ant 插件,它可以工作。但我不确定这是否是最好的方法。
  • 您的 Maven 配置为查找哪些存储库?其他构建(从中获取 EAR 文件)在哪里部署工件 (EAR)?如果它们不是相同的存储库,您可能需要在 settings.xml 中配置另一个存储库。或者只是将工件结构复制到本地 Maven 存储库。

标签: maven ear


【解决方案1】:

您可以使用dependency:unpack-dependencies 来完成。我只是修改了我的答案,因为根据您的 cmets,您的耳朵是由其他构建生成的。如果您没有可以部署您的 ear 工件的 Enterprise 存储库,则必须使用“系统”范围,但请注意,它通常不鼓励

将以下依赖项添加到您的 pom.xml

<dependency>
    <groupId>ECM</groupId>
    <artifactId>ECM</artifactId>
    <version>1.0</version>
    <type>ear</type>
    <scope>system</scope>
    <systemPath>/path/to/your/abc.ear</systemPath>
</dependency>

将以下插件添加到您的 postBuild 模块 pom.xml

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>unpack</id>
            <phase>package</phase>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
                <includeArtifactIds>ECM</includeArtifactIds>
                <outputDirectory>${project.build.directory}/earoutput</outputDirectory>
            </configuration>
        </execution>
    </executions>
 </plugin>

【讨论】:

    【解决方案2】:

    【讨论】:

    • 是的。我不确定为 groupId 指定什么。我保持原样并得到错误,因为 Artifact[sar:artifactGroupId:ECM] 不是项目的依赖项
    • 这假设您的 EAR 文件作为工件存在于 Maven 存储库中。
    • 好的。如何指定 EAR 文件的确切位置?
    • 您只需要在模块部分指定正确的artifactIdgroupId。工件应该存在于 Maven 配置的任何存储库中。另外,我不确定sarModule 是什么。你试过earModule吗?
    【解决方案3】:

    Maven Dependency Plugin 及其unpack 目标可以做到这一点。

    示例配置:

    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-dependency-plugin</artifactId>
     <version>2.6</version>
     <executions>
       <execution>
         <id>unpack</id>
         <phase>package</phase>
         <goals>
           <goal>unpack</goal>
         </goals>
         <configuration>
           <artifactItems>
             <artifactItem>
               <groupId>myear</groupId>
               <artifactId>myear</artifactId>
               <version>1.0</version>
               <type>ear</type>
             </artifactItem>
           </artifactItems>
           <outputDirectory>${project.build.directory}/earoutput</outputDirectory>
         </configuration>
       </execution>
     </executions>
    </plugin>
    

    这将获取“myear.ear”工件并将其提取到“target/earoutput”目录。这也适用于 JAR、WAR 和任何其他类似 zip 的文件。执行的阶段是“包”——如果您需要在构建的其他部分使用这些资源,这可能为时已晚。如果需要,将阶段更改为更早的内容,例如“生成资源”。

    您提到您已经尝试使用依赖插件。 EAR 文件是否来自另一个 Maven 项目,是否已安装在本地 Maven 存储库中?如果它仍然不起作用,请发布您尝试使用的插件配置。


    (编辑:更新依赖和本地存储库的信息)

    为此,需要将您的 EAR 文件放入本地 Maven 存储库(这只是您磁盘上的一个目录)。但如果其他人也需要构建您的项目,您有以下几种选择:

    • 将 EAR 导入您的本地存储库,并部署到远程存储库,以便每个人都可以获取它(推荐,但需要您设置企业 Maven 存储库)
    • 将 EAR 提供给每个人,并让他们使用几个 Maven 命令将其放入本地存储库(对于少数开发人员来说可能没问题,比设置整个存储库服务器的开销更少)
    • 将依赖的 EAR 检入到项目下的源代码控制中,并将其解压缩(不是推荐的处理方式)到项目的目标中

    导入本地存储库很容易。它与these instructions 非常相似。

    使用以下命令:

    mvn install:install-file -Dfile=<path-to-EAR-file-on-local-filesystem> -DgroupId=myear
    -DartifactId=myear -Dversion=1.0 -Dpackaging=ear
    

    (根据需要修改路径、groupId、artifactId 和版本)

    组 ID 和工件 ID 只是为了唯一标识工件。

    在本地存储库中安装它后,依赖插件应该可以工作并找到工件。

    【讨论】:

    • 我不明白 groupId、artifactId 和 version 标签是什么意思。我的 EAR 文件来自一些我从某处下载并想要提取内容的构建。它与这个 maven 项目无关。
    • @SairamSankaran 添加了一些关于将 EAR 安装到本地存储库的信息
    猜你喜欢
    • 2011-03-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 2013-07-07
    • 1970-01-01
    相关资源
    最近更新 更多