操作系统: Windows 7 x64
月食平台: 3.7.2.M20120208
m2e: 1.0.200.20111228-1245
有类似于这个bug中的问题。在package-info.java和/test文件夹中有一堆/src文件,所以它们有相同的包。Eclipse显示错误:
"The type **package-info** is already defined"我可以删除package-info.java文件,无论是在/test还是/src,以避免问题指示。但是这个解决方法并不是很舒服,因为我正在使用SCM,并且需要在更新后随时删除这个文件。Eclipse 4.2.0.I20120608-1400相同
发布于 2014-01-08 02:14:26
要解决这个问题,有几种选择:
发布于 2014-11-05 14:27:00
你能做到的->
转到生成路径->配置生成路径->
在Source选项卡中->
选择包(其中有这些有问题的包-info.java文件)。项目名称/src/test/java
点击排除->并在排除模式中添加"**/package-info.java“
这应该可以解决问题,因为您显然是在要求eclipse排除这些文件,因此您不必删除这些文件并解决与SCM相关的问题。
发布于 2016-01-30 12:05:33
如果您使用maven和m2e进行eclipse和maven之间的交互。有一个非常干净的解决方案:向pom.xml添加一个仅由m2e激活的配置文件,并防止在测试编译阶段编译Packy-info.java。这里有一个样本:
<profile>
<id>m2e</id><!--This profile is activated when eclipse interacts with maven (using m2e).-->
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<!--eclipse do not support duplicated package-info.java, in both src and test.-->
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<configuration>
<testExcludes>
<exclude>**/package-info.java</exclude>
</testExcludes>
</configuration>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>https://stackoverflow.com/questions/11246223
复制相似问题