【问题标题】:Maven: use jar from URL as a source for resourcesMaven:使用来自 URL 的 jar 作为资源的来源
【发布时间】:2013-01-29 00:06:30
【问题描述】:

处理遗留项目,我需要从 URL 的 jar 加载文本资源。 然后将过滤文本资源并包含在输出中;这些资源来自已发布的工件。

从资源插件我看到只能提供一些目录;是否可以根据需要加载资源?

我想做这样的事情,但使用远程 jar 而不是工作区中的其他项目:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
    <execution>
    <id>copy-resources</id>
    <phase>process-resources</phase>
    <goals>
        <goal>copy-resources</goal>
    </goals>
    <configuration>
        <outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory>
                        <resources>
                            <resource>
                                <directory>../<another project on the same workspace>/src/main/filtered-resources</directory>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

远程资源插件,正如其中一个答案所建议的那样不起作用,因为导入的包中没有文件最终出现在目标中;我无法使用远程资源插件生成原始捆绑包(它是一个仍在使用且完全不受我控制的遗留项目)。

【问题讨论】:

  • 您能否更新一下为什么“远程资源插件”不能满足您的需求?干杯。
  • 完成了,基本上什么都不做

标签: maven


【解决方案1】:

我认为Maven Remote Resources Plugin 将满足您的需求。

编辑

从插件的usage page 获得的片段。该 XML 片段会将插件附加到 generate-sources 阶段(如果它不适合您的需要,请选择不同的),将下载 apache-jar-resource-bundle 工件并将其内容解压缩到 ${project.build.directory}/maven-shared-archive-resources

为了获得更好的结果,建议使用同一插件的bundle 目标创建资源工件。

<!-- Turn this into a lifecycle -->
<plugin>
  <artifactId>maven-remote-resources-plugin</artifactId>
  <version>1.4</version>
  <executions>
    <execution>
      <id>process-remote-resources</id>
      <phase>generate-sources</phase>
      <goals>
        <goal>process</goal>
      </goals>
      <configuration>
        <resourceBundles>
          <resourceBundle>org.apache:apache-jar-resource-bundle:1.0</resourceBundle>
        </resourceBundles>
      </configuration>
    </execution>
  </executions>
</plugin>

编辑 2:使用 AntRun 的替代解决方案

如果您的工件不适合 Maven 的需求,并且您需要更多定制的东西,那么使用 AntRun 插件您可以通过某种方式获得它:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.7</version>
  <executions>
    <execution>
      <id>download-remote-resources</id>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <target>
          <get src="URL of the resource" dest="${project.build.directory}" />
          <unzip src="${project.build.directory}/filename.[jar|zip|war]" dest="${project.build.directory}/${project.build.finalName}" />
        </target>
      </configuration>
    </execution>
  </executions>
</plugin>

【讨论】:

  • 我不认为它会起作用:我会更详细地更新问题
  • @RiccardoCossu 你至少试过了吗?期待这个问题的更新
  • @RiccardoCossu 添加了替代解决方案
  • 谢谢,这应该可以解决问题(某些黑客对于遗留项目来说是必要的邪恶;我希望避免它们);我不能确定它是否会起作用,因为我对那个项目有更严重的问题......
猜你喜欢
  • 1970-01-01
  • 2019-09-21
  • 2011-01-28
  • 2011-10-10
  • 2023-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-30
相关资源
最近更新 更多