[英]Cannot import java classes under src/main/java into src/test/java in eclipse
I am using maven project in Eclipse, where I am not able to access classes under src/main/java in src/test/java class.我在 Eclipse 中使用 maven 项目,我无法访问 src/test/java 类中 src/main/java 下的类。 I could use the classes in maven dependacies jars though.不过,我可以在 Maven 依赖项 jar 中使用这些类。 What am I missing ?我错过了什么?
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..或者只是把它们都放在这里..
You just need to import
them.您只需要import
它们。 Eclipse should help you with this: if you try to use the class names, it'll suggest where to import from. Eclipse 应该可以帮助您解决这个问题:如果您尝试使用类名,它会建议从何处导入。
The test classes are a separate package, so the classes will need to be declared public
.测试类是一个单独的包,因此需要将这些类声明为public
。
Absolutely, one can do it..绝对可以的..
First You need to navigate to Build Path-->Configure Build Path--> Source tab首先,您需要导航到 Build Path-->Configure Build Path--> Source 选项卡
then in the Source tab search/check [your Project Name]/src/main/java and change然后在 Source 选项卡中搜索/检查 [your Project Name]/src/main/java 并更改
"contains test sources" from No to Yes and save it. “包含测试源”从“否”到“是”并保存。
This will resolved issue of import packages from "src/test/java" to "src/main/java" successfully这将成功解决从“src/test/java”导入包到“src/main/java”的问题
Project -> Clean项目 -> 清洁
is enough for me to work足以让我工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.