Maven / M2Eclipse 总是排除我的资源
我在 Maven-Eclipse 集成方面遇到两个非常烦人的问题,它有时会从构建路径中排除 src/main/resources 和 src/test/resources 中的所有资源。
如果我检查“属性>> Java构建路径>>源”,我可以看到这两个文件夹具有“排除:**”。
通过单击排除项上的“删除”可以轻松解决该问题,但这确实非常令人沮丧。
项目设置非常简单,它有一些模块和子模块,但没什么花哨的。我的 pom.xml 中没有任何有关资源、Eclipse 或其他内容的配置选项(也许我应该?)。
另一个问题是 Eclipse 不断在“目标”目录中(在“问题”视图中)报告警告,而它一开始就不应该在意。
PS:Springsource工具套件2.7.0.RELEASE、Maven Integration for Eclipse 0.12.1.20110112、Maven 2.2.1
I have two very annoying issues with Maven-Eclipse integration, from time to time it excludes all my resources in src/main/resources and src/test/resources from the build path.
If I inspect "Properties >> Java Build Path >> Source" I can see that these two folders have "Excluded: **".
The problem can be easily solved by clicking on "Remove" on the exclusions, but it is really-really frustrating.
The project setup is very simple, it has some modules and sub-modules, but nothing fancy. I don't have any configuration options in my pom.xmls regarding resources, eclipse or whatever (maybe I should?).
The other problem is that Eclipse keeps reporting warnings in the "target" directories (in the "Problems" view), where it shouldn't give a damn in the first place.
Ps: Springsource Tool Suite 2.7.0.RELEASE, Maven Integration for Eclipse 0.12.1.20110112, Maven 2.2.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是正确的行为。当前版本的 M2E 为 Eclipse IDE 内的自动构建过程提供了自己的贡献者。此构建过程考虑了生成资源和进程资源等的 Maven 生命周期...即某些项目具有从配置生成资源并放入编译后的输出文件夹中的插件。
您在构建路径中看到的机制仅与 Eclipse IDE 内置机制相关,用于将一组输入源文件夹编译/组装到输出文件夹中。如果 Maven 和 Eclipse 都这样做,就会出现冲突/问题。
M2E 常见问题解答中有一个关于这一点的链接 https://www.eclipse.org/m2e/documentation/m2e-faq.html#how-to-configure-proxy-and-location-of-maven-local-repository
如果你真的遇到资源未被复制的问题,也许我们可以解决原因(因为这是另一回事),但您的主要问题是关于常见的 M2E 常见问题解答点。
也许您想升级到 org.eclipse.m2e 和 Indigo,因为我遇到的许多 Maven 复杂 Maven 问题/使用大部分已得到解决或有解释的解决方案。
。
我建议您执行“Run As -> Maven -> clean”,然后执行“Project -> Clean”,然后启用自动构建(这是为了允许基于 Eclipse 的自动构建发生,不要使用 Run As -> 构建 Maven 来测试这一点)。现在在 Eclipse 外部打开文件管理器,并手动检查输出文件夹中是否存在您认为未复制的资源。你应该会发现它们都在那里。
。
我同意有关 target/** 目录中项目的(可能是验证)警告,虽然 Eclipse 有一种方法可以手动从验证中排除 target/** 目录,但此选项不会超出项目清理范围(当目标目录为已删除)。
因此,在大型项目中总是等待项目的验证有点烦人。
也许我尝试看看是否可以创建 Maven Eclipse 连接器插件来执行此操作,即绑定到构建生命周期并自动在目标文件夹上应用排除验证。
This is correct behavior. Current version of M2E provide their own contributor to the automatic build process inside the Eclipse IDE. This build process takes into account the maven lifecycle for generate-resources and process-resources etc... i.e. some project have plugins that generate resources from configuration and put in the compiled output folder.
The mechanism you are looking at in the Build Path only relates to the Eclipse IDEs built in mechanism to compile/assembly a set of input source folders into the output folders. If both Maven and Eclipse did this there would be conflicts/problems.
There is a link in the M2E FAQ about this exact point https://www.eclipse.org/m2e/documentation/m2e-faq.html#how-to-configure-proxy-and-location-of-maven-local-repository
If you are genuinely having problems with resources not being copied maybe we can work through why that is (since that is another matter), but your main question is about a common M2E FAQ point.
Maybe you want to upgrade to org.eclipse.m2e and Indigo as a lot of Maven complex maven issues/usage I have are mostly resolved or have an explained solution.
.
I would recommend you perform a "Run As -> Maven -> clean" and then a "Project -> Clean" then enable automatic bulding (this is to allow Eclipse based automatic build to take place, do not use Run As -> Maven to build to test this point). Now open a file manager outside eclipse and manually inspect the output folders for the resources that you did not think are being copied. You should find they are there just the same.
.
I agreed with the (probably Validation) warning about items in the target/** directory and whilst Eclipse has a way to manually exclude the target/** directory from validation this option does not stick beyond a project clean (when the target directory is deleted).
So it is somewhat annoying to be always waiting for validation of items in a large project.
Maybe I attempt to see if a Maven Eclipse connector plugin can be created provided to do this i.e. tie into the build lifecycle and automatically apply the Exclude Validation on the target folder.
T_T不是一个好的解决方案。如果没有 maven-update maven resources:resources 阶段在生命周期映射中标记为忽略,则不会复制资源
将导致此问题。
正如 Miles 上面指出的,eclipse 不会复制资源,因为它假设 Maven 会为您做这件事。然后,如果在 maven 中执行此工作的 resources:resources 阶段未执行,则会在运行时出现文件未找到异常。
检查这个打开的
项目->属性->maven->生命周期映射
并查看 resources:resources 是否被标记为忽略。
解决这个问题 windows->首选项->maven->生命周期映射->打开工作空间生命周期映射元数据,
然后更改
为
目标
资源
重新加载元数据和更新maven项目
应该可以解决问题。
T_T not a good solution. resources is not copied without maven-update
maven resources:resources phase marked ignored in Lifecycle Mappings will cause this problem.
As Miles pointed out above, eclipse don't copy the resource since it assumes maven will do it for you. Then if resources:resources phase which do the job in maven is not executed, you get a file not found exception at runtime.
to check this open
project->properties->maven->lifecycle mapping
and see whether resources:resources is marked ignored or not.
to solve it windows->preference->maven->lifecycle mapping-> open workspace lifecycle mappings metadata
then change
to
for goal
resources
reload metadata & update maven project
should solve the problem.
步骤1.从eclipse中删除项目
步骤2.重新导入项目
步骤 3. 转到需要添加为源文件夹的文件夹。
请参考下面的屏幕截图:
step 1. delete the project from eclipse
step 2. import the project freshly
step 3. Go to the folder required to be added as source folder.
Please refer below screen shot: