eclipse eclipse中无法将src/main/java下的java类导入到src/test/java中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27421838/
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
Cannot import java classes under src/main/java into src/test/java in eclipse
提问by Kedarnath
I am using maven project in Eclipse, where I am not able to access classes under src/main/java in src/test/java class. I could use the classes in maven dependacies jars though. What am I missing ?
我在 Eclipse 中使用 maven 项目,在那里我无法访问 src/test/java 类中 src/main/java 下的类。不过,我可以在 Maven 依赖项 jar 中使用这些类。我错过了什么?
回答by Daniel Stanley
I have found that sometimes this error appears and by simply going Project -> Clean...
the error will stop.
我发现有时会出现这个错误,只要继续Project -> Clean...
,错误就会停止。
However if this does not work there is a blog with some more suggestions here
然而,如果这不起作用有一些更多的建议,一个博客在这里
Updated 11/07/2017
2017 年 7 月 11 日更新
The original link is no longer available, refer to web archive here
原始链接不再可用,请参阅此处的网络存档
Or just have them all here..
或者只是把它们都放在这里..
- ‘Clean' Your Eclipse Project: Go to Project > Clean in Eclipse [This seems to work for me]
- Refresh your project folder (right click on your project > refresh)
- Re-build your project
- Clean your builds (If using Ant or Maven – clean your builds)
- Recreate your project in Eclipse
- ‘Switch' Workspace – then Switch back (Eg Change to Debug, then switch back to Java)
- Remove and re-add your JRE:
- Right Click on your project > properties
- Click on the Libraries tab
- Click on the JRE
- Click remove, then OK
- Repeat 1-3 again, but add the JRE again
- “清理”您的 Eclipse 项目:在 Eclipse 中转到“项目”>“清理”[这似乎对我有用]
- 刷新您的项目文件夹(右键单击您的项目> 刷新)
- 重新构建你的项目
- 清理你的构建(如果使用 Ant 或 Maven – 清理你的构建)
- 在 Eclipse 中重新创建您的项目
- “切换”工作区 - 然后切换回(例如更改为调试,然后切换回 Java)
- 删除并重新添加您的 JRE:
- 右键单击您的项目 > 属性
- 单击库选项卡
- 单击 JRE
- 点击删除,然后确定
- 再次重复 1-3,但再次添加 JRE
回答by chiastic-security
You just need to import
them. Eclipse should help you with this: if you try to use the class names, it'll suggest where to import from.
你只需要import
他们。Eclipse 应该可以帮助您解决这个问题:如果您尝试使用类名,它会建议从何处导入。
The test classes are a separate package, so the classes will need to be declared public
.
测试类是一个单独的包,因此需要声明这些类public
。
回答by Java by kiran
Project -> Clean
项目 -> 清洁
is enough for me to work
足以让我工作