Java Maven clean + build 导致 Eclipse 中的项目显示错误,直到 Eclipse 中的 clean
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9698465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven clean + build causes project in Eclipse to show errors until clean in Eclipse
提问by Enrico
We are getting a very weird behavior in our development environment that is consistent with all of our developers on different operating systems.
我们的开发环境中出现了一种非常奇怪的行为,这与我们在不同操作系统上的所有开发人员一致。
We have about 20+ Maven (3.0.4) projects in the development environment, all of them are open projects in Eclipse (Indigo) with sonatype m2e (0.12.0) handling dependencies as usual. (m2e 1.0 is causing us more problems than solutions)
我们在开发环境中有大约 20 多个 Maven (3.0.4) 项目,它们都是 Eclipse (Indigo) 中的开放项目,sonatype m2e (0.12.0) 照常处理依赖项。(m2e 1.0 给我们带来的问题多于解决方案)
Out of all our 20+ projects there is one projectthat's acting weird.
When performing mvn clean install
on that project, even though Maven passes successfully, it causes 4 java files (in the unit tests, if it makes any difference) to show errors in Eclipse.
在我们所有的 20 多个项目中,有一个项目表现得很奇怪。mvn clean install
在该项目上执行时,即使 Maven成功通过,它也会导致 4 个 java 文件(在单元测试中,如果有任何不同)在 Eclipse 中显示错误。
The errors are of the type "SomeNameOfClass cannot be resolved to a type" although opening the file and pressing F3 (Open declaration) on the erroneous class reference finds the class without a problem.
尽管打开文件并在错误的类引用上按 F3(打开声明)会发现该类没有问题,但错误属于“无法将 SomeNameOfClass 解析为类型”类型。
mvn clean
is the problem, if we just run mvn install
this doesn't happen.
mvn clean
是问题,如果我们只是运行mvn install
这不会发生。
Eclipse's Project -> Clean clears the errors and everything is ok.
Eclipse 的 Project -> Clean 清除了错误,一切正常。
This is notan operational problem that actually prevents me from working or anything like that, I can solve itsimply by cleaning in Eclipse, I just hate doing that every time and I can't stand red Xs in my projects even if they have no effect.
这不是一个实际阻止我工作或类似的操作问题,我可以通过在 Eclipse 中简单地清理来解决它,我只是讨厌每次都这样做,即使他们没有,我也无法忍受我的项目中的红色 X影响。
I'm just really really curious why this is happening at all, why specifically those 4 classes? why why why? :)
我真的很好奇为什么会发生这种情况,为什么特别是那 4 个类?为什么为什么为什么?:)
采纳答案by GETah
We have had the exact same problem a while ago. We had more than 20 projects giving the same kind of error. From the investigation we did, we concluded that when maven clean install
is run, eclipse loses track of the class files and thinks some of them are undefined.
The solution we had is to issue the following at the command line:
不久前我们遇到了完全相同的问题。我们有 20 多个项目出现了同样的错误。根据我们所做的调查,我们得出的结论是,在maven clean install
运行时,eclipse 会丢失对类文件的跟踪,并认为其中一些是未定义的。我们的解决方案是在命令行中发出以下命令:
mvn eclipse:clean
mvn clean install
mvn eclipse:eclipse
回答by Ludovic Guillaume
This is now possible to specify that project(s) needs a refresh upon completion under Refresh
tab in Run configuration
. You will have to check Refresh resources upon completion
and select which behavior below.
现在可以在 中的Refresh
选项卡下指定项目在完成时需要刷新Run configuration
。您必须检查Refresh resources upon completion
并选择下面的行为。
回答by Geoffrey Ritchey
I've found that having a jar in maven as 'test' scope will cause the "unresolved type" error and nothing I've found yet will fix it other than take it out of test scope in the pom file.
我发现在 maven 中有一个 jar 作为“测试”范围会导致“未解析的类型”错误,我发现的任何东西都不会修复它,除了将它从 pom 文件中的测试范围中取出。
回答by Abhi
If you want to get rid of errors through UI, do the following steps:
如果您想通过 UI 消除错误,请执行以下步骤:
Select your project in eclipse and do ALT + ENTEROR right click on project -> Build path -> Configure Build Path
在 Eclipse 中选择您的项目并执行ALT + ENTER或右键单击项目 ->构建路径 -> 配置构建路径
Select Java Build Pathoption and Sourcetab.
选择Java Build Path选项和Source选项卡。
Select node(s) for which it shows error e.g. src/main/java and click Removeand Click Apply.
选择显示错误的节点,例如 src/main/java 并单击Remove并单击Apply。
Again add the same(removed) node(s) using Add Folderoption and click Apply and Closebutton.
再次使用添加文件夹选项添加相同(已删除)的节点,然后单击应用和关闭按钮。
Error(s) should have disappeared!
错误应该已经消失了!