Eclipse(Maven)中的Junit软件包命名冲突 [英] Junit package naming conflict in Eclipse (Maven)
问题描述
我想在我的junit测试中使用默认的Maven目录,所以:
I want to use the default maven directories for my junit tests, so:
- 在Eclipse中,我创建了一个
test/java
文件夹. - 我在其中用
package com.xxx.xxx.tracker.utils.test;
创建了一个junit类
- in Eclipse I created a
test/java
folder. - I created a junit class in there with a
package com.xxx.xxx.tracker.utils.test;
但是日食给我一个错误.它想将包名称更改为
But eclipse is giving me an error. It wants to change the package name to
package test.java.com.xxx.xxx.tracker.utils.test;
或者eclipse要我将其移动到与com/xxx/xxx/tracker/utils/test
Or eclipse wants me to move it to a folder that corresponds to com/xxx/xxx/tracker/utils/test
这是来自eclipse的确切消息:
Here is the exact message from eclipse:
- 声明的软件包"com.xxx.xxx.tracker.utils.test"与预期的软件包"test.java.com.xxx.xxx.tracker.utils.test"不匹配
- 提供2个快速修复程序
- 将xxxTest.java移动到打包com.xxx.xxx.tracker.utils.test"
- 将包声明更改为"test.java.com.xxx.xxx.tracker.utils.test"
- The declared package "com.xxx.xxx.tracker.utils.test" does not match the expected package "test.java.com.xxx.xxx.tracker.utils.test"
- 2 quick fixes available
- Move xxxTest.java to 'package com.xxx.xxx.tracker.utils.test'
- Change package declaration to 'test.java.com.xxx.xxx.tracker.utils.test'
我想将junit保留在test/java文件夹中,以使其脱离构建并遵循约定,但在程序包名称中包含test.java
并没有任何意义.
I want to keep the junit in the test/java folder to keep it out of the build and follow convention, but it does not make sense to have test.java
in my package name.
有没有一种方法可以将程序包名称保留为我想要的方式,并将其保存在test/java文件夹中?
Is there a way to keep the package name the way I want and also have it in the test/java folder?
编辑:是因为我的"src"文件夹中有项目吗?例如:
Is it because I have projects in my 'src' folder? For example:
src/
com.xxx.xxx.tracker.utils.Xxxx.java
test/
java/
com.xxx.xxx.tracker.utils.XxxxTest.java
这个项目不是从Maven开始的.它是由其他人转换的.
This project did not start out with Maven. It was converted by someone else.
编辑2 :更多的火苗:
这是我pom.xml中的内容(我没有设置).
Here is something from my pom.xml (which I did not set up).
<build>
<sourceDirectory>/home/me/workspace/proj_PARENT/proj_Classes/src</sourceDirectory>
<testSourceDirectory>/home/me/workspace/proj_PARENT/proj_Classes/src/test/java</testSourceDirectory>
我确实有eclipse m2e插件.
I do have the eclipse m2e plugin.
推荐答案
您对结构和类路径有疑问.使用您描述的布局,文件夹src是您的源代码的根目录.但是它包含测试,应该放在子文件夹中.在您的情况下,您有嵌套的源文件夹.这必须导致编译问题,因为* .java文件将存在于两个软件包中.其中一个软件包无效.
You have a problem with you Structure and your classpath. With your descripbed layout the folder src is the root of your sources. But it contains the tests, which should be in a subfolder. In your case you have nested source folder. This MUST lead into compile problems, because a *.java file will be present in two packages. One of the packages is invalid.
src/
com.xxx.xxx.tracker.utils.Xxxx.java
test/
java/
com.xxx.xxx.tracker.utils.XxxxTest.java
现在您应该创建两个src文件夹.
Now you should create two src-folder.
src/
main/
java/
com.xxx.xxx.tracker.utils.Xxxx.java
test/
java/
com.xxx.xxx.tracker.utils.XxxxTest.java
这篇关于Eclipse(Maven)中的Junit软件包命名冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!