【问题标题】:build-helper-maven-plugin add-source does not working when trying to add linked resources尝试添加链接资源时,build-helper-maven-plugin add-source 不起作用
【发布时间】:2012-08-08 06:13:14
【问题描述】:

我是 maven 新手,一开始遇到了一个看起来很容易的问题,但我已经让我忙了一整天,没有办法让它工作。

首先,作为运行 eclipse:eclipse 插件的一部分,我创建了一个链接文件夹,如下所示:

<linkedResources>
<linkedResource>
    <name>properties</name>
    <type>2</type>
    <location>${PARENT-2-PROJECT_LOC}/some_other_project/properties</location>
</linkedResource>
<linkedResource>
    <name>properties/messages.properties</name>
    <type>1</type>
    <location>${PARENT-2-PROJECT_LOC}/some_other_project/properties/messages.properties</location>
</linkedResource>

然后我将该文件夹添加为源文件夹,如下所示:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
  <execution>
    <id>add-source</id>
    <phase>generate-sources</phase>
    <goals>
      <goal>add-source</goal>
    </goals>
    <configuration>
      <sources>
        <source>properties</source>
        <source>some_real_folder</source>
      </sources>
    </configuration>
  </execution>
</executions>
</plugin>

但是,当我在 Eclipse 中查看生成的 .classpath 时,“some_real_folder”在那里,但“properties”却没有。看起来默认情况下 build-helper-maven-plugin 会检查文件夹是否存在,如果不存在则不会添加它。

我在 Eclipse 之外使用 maven 3.0.4 来运行构建,我可以在 maven 日志中看到如下内容:

[INFO] Source directory: <some path>\properties added.

这是我的项目结构:

project1 
  \-- properties (this is the real folder) 

project2
   \-- some_real_folder
   \-- properties (this is the link resource pointing to the project1/properties folder)

我只需要将“some_real_folder”和链接资源“properties”都添加到项目2的.classpath中

【问题讨论】:

  • 你能展示一下你项目的目录结构吗?您使用哪个 Eclipse 版本?你用m2e吗?
  • 展示的并不多。我有: project1 \-- 属性(这是真正的文件夹) project2 \-- some_real_folder \-- 属性(这是链接资源) 我需要“some_real_folder”和链接的资源“属性”作为 . project2的类路径
  • 抱歉,不知道如何让它看起来更漂亮。
  • 只需在此处编辑您的帖子,您就可以获得更好的格式。

标签: maven maven-eclipse-plugin


【解决方案1】:

将来自人工制品外部的东西直接包含到人工制品中是一种不好的做法。您应该只将文件夹 project2 下的 project2 内容和 project2 依赖项中的内容包含到 project2 中。 (我不确定你正在做的事情是否可行。)

所以,如果你想让 project1/properties 在 project2 中可用,你通常将 project1/properties 打包到 project1 的 artefact 中,并将对 project1 的依赖添加到 project2 中。如果由于某种原因这不起作用(例如,因为您想将 project1 的东西移动到 project2 中的另一个位置),您可以使用 maven-dependency-plugindependency:copy-dependencies 将其解压到 project2 的目标中到某个适当的位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 2019-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多