Eclipse 中的 Maven Eclipse 插件和类路径问题
我正在使用 Eclipse 3.51、Maven 2.0.9、Java 1.4、Maven Eclipse 插件 2.7 和 WTP 2.0(不是 m2Eclipse)。
我有一个平面多模块项目,设置如下(模块 Parent 具有父 pom,模块 A 和 B 依赖于 C)。
由于我没有运行 eclipse 插件,第一次导入这四个模块将按预期显示编译错误。当我的本地存储库为空时,运行 eclipse clean 将解决本地工作区中的所有编译错误和依赖项。
如果我对模块 B 进行一些小的代码更改并再次运行 eclipse 插件,则模块 A 和 B 中将出现编译错误。有关找不到类的编译错误。就像模块 C 不再位于 A 和 B 的类路径中一样。
我查看了 .classpath 文件,它确实查看了 Eclipse 工作区中的正确模块。
如果我删除 Maven 存储库并再次执行 Eclipse Clean,则有关未解析类的编译错误将得到修复。另外,如果我运行 eclpse clean 命令,并将 useProjectReferences 标志设置为 false,然后使用 true 重新运行它,Eclipse 将重建我的工作区,并且错误将消失。
这是怎么回事?
I am using Eclipse 3.51, Maven 2.0.9, Java 1.4, with the Maven Eclipse plugin 2.7 with WTP 2.0 (not m2Eclipse).
I have a flat multi module project that is set up as follows (module Parent with the parent pom, module A and B is dependent on C).
Importing the four modules in for the first time will show compile errors as expected since I have not ran the eclipse plugin. With my local repository empty, running eclipse clean will resolve all compile errors and dependencies within the my local workspace.
If I were to make some minor code changes to module B and run the eclipse plugin again, compile errors would show up in module A and B. Compile errors about classes that cannot be found. Its like module C is no longer in the classpath for A and B to see.
I look at the .classpath file and its definitely looking at the right modules in the Eclipse workspace.
If I delete the maven repository and do the eclipse clean again, the compile errors about unresolved classes are fixed. Also, if I run the eclpse clean command with the useProjectReferences flag to false and then rerun it with true, Eclipse would rebuild my workspace and the errors will go away.
Whats going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止,一切都很好。只有一个问题:通过 eclipse clean,您并不是指 eclipse:clean,而是指 Eclipse 下的 clean,对吧?
我不确定为什么你在对模块 B 进行较小的代码更改后运行 Maven Eclipse 插件,但是,假设你必须这样做,因为你添加了一个依赖项(提及你运行的目标会很有帮助,但没关系)。当使用maven eclipse插件进行多项目构建时,默认情况下它将在Eclipse级别使用项目引用(即A和B依赖于C的编译类,而不是C JAR)。而且由于 Maven 和 Eclipse 共享相同的
target/classes
文件夹,因此在 Maven 级别进行清理或编译可能会使 Eclipse 感到困惑。它不再看到已编译的类,也不会自己编译它们(因为 Eclipse 中没有发生更改)。在这种情况下,Eclipse 清理或重建(即在 Eclipse 级别)应该可以解决问题。是的,这不是问题。问题在于 Eclipse 和 Maven 共享相同的编译类文件夹。
你真的不必这样做,如果你使用项目引用,我不明白 Maven 存储库与此有什么关系。在 Eclipse 下执行清理和/或重建所有项目应该可以解决该问题。
您是否使用项目参考?同样,下次,也许在您的问题中提供您的插件配置,这可能会有所帮助。无论如何,您不必在构建之间触及它。决定是否要使用项目引用(我认为这更方便,没有它们,您将需要
mvn install
C 以使更改可用于 A 和 B)并坚持使用此配置。在mvn
构建之后,重建 Eclipse 工作区就足够了。PS:请注意,您可以配置 Maven Eclipse 插件以使用自定义
buildOutputDirectory
,例如target/eclipse-classes
但这还有其他缺点(我没有这样做)。So far so good. Just one question: by eclipse clean, you don't mean
eclipse:clean
but clean under Eclipse, right?I'm not sure why you run the maven eclipse plugin after a minor code changes to module B but, let's say you have to e.g. because you added a dependency (it would have been helpful to mention the goal you run but never mind). When using the maven eclipse plugin with a multi projects build, it will use project references by default at the Eclipse level (i.e. A and B depend on the compiled classes of C, not on C JAR). And because Maven and Eclipse share the same
target/classes
folder, a clean or compile at the Maven level can confuse Eclipse. It doesn't see the compiled classes anymore and won't compile them by himself (because the change didn't occur in Eclipse). In that case, an Eclipse clean or rebuild (i.e. at the Eclipse level) should solve the problem.Yes, that's not the problem. The problem comes from the fact that both Eclipse and Maven share the same folder for compile classes.
You really don't have to do this and I don't get what the maven repository has to do with this if you use project references. Performing a clean and/or rebuilding all projects under Eclipse should fix the problem.
Are you using project references or not? Again, next time, maybe provide your plugin configuration in your question, this may help. Anyway, you should not have to touch this between builds. Decide if you want to use project references (I think it's more convenient, without them you'll need to
mvn install
C to make changes available for A and B) and stick with this configuration. After amvn
build, a rebuild of the Eclipse workspace should be enough.PS: Note that you could configure the maven eclipse plugin to use a custom
buildOutputDirectory
, for exampletarget/eclipse-classes
but this has other drawbacks (I wasn't doing this).