如何应对在安卓/ Maven项目缺少的src /测试/ java源文件夹?源文件、如何应对、测试、项目

2023-09-04 02:57:40 作者:丶落败的浮夸

我不是非常有经验与Maven与Android的组合,因此我跟着这些的说明进行新的Andr​​oid项目。当已创建项目,我收到以下错误信息:

I'm not very experienced with Maven in combination with Android yet, so I followed these instructions to make a new Android project. When the project has been created, I get the following error message:

项目XXX-1.0-快照缺少所需的源文件夹:   SRC /测试/ java的

Project 'xxx-1.0-SNAPSHOT' is missing required source folder: 'src/test/java'

当我尝试添加一个新的源文件夹中新建 - >其他 - > Java的源文件夹使用的src /测试/ java中,我得到另一个错误信息:

When I try to add a new source folder with New->Other->Java-Source Folder with src/test/java, I get another error message:

文件夹已经是源文件夹。

The folder is already a source folder.

不过,我没有任何的src /测试/ java文件夹在我的项目。我应该如何处理呢?什么是干净的方式来设置这个项目,是因为我认为也有一些是在该指令失踪。那么,什么是Maven的方法,让SRC /测试/ java的出现?

But I don't have any src/test/java folder in my project. How should I deal with that? What's the clean way to setup the project, because I assume that there is something missing in this instruction. So what is the Maven way to let src/test/java appear?

我使用Eclipse的Juno,M2E 1.1.0,Android的配置M2E 0.4.2。

I'm using Eclipse Juno, m2e 1.1.0, Android Configuration for m2e 0.4.2.

推荐答案

我意识到这恼人的事情太多,因为最新的M2E-Android插件升级(0.4.2版本),它发生在这两个新项目的创建和现有项目导入(如果你不使用的src /测试/爪哇)。

I realise this annoying thing too since latest m2e-android plugin upgrade (version 0.4.2), it happens in both new project creation and existing project import (if you don't use src/test/java).

它看起来像M2E-机器人(或者M2E)现在总是试图添加的src /测试/ java的作为源文件夹,无论是实际存在的项目目录,在.classpath文件:

It looks like m2e-android (or perhaps m2e) now always trying to add src/test/java as a source folder, regardless of whether it is actually existed in your project directory, in the .classpath file:

<classpathentry kind="src" output="bin/classes" path="src/test/java">
  <attributes>
    <attribute name="maven.pomderived" value="true"/>
  </attributes>
</classpathentry>

因为它是在项目的元数据文件已经增加,因此,如果你想添加通过Eclipse的源文件夹,Eclipse会抱怨classpathentry是已经存在的:

As it is already added in the project metadata file, so if you trying to add the source folder via Eclipse, Eclipse will complain that the classpathentry is already exist:

有几种方法可以解决这个问题,最简单的是手动在文件系统中创建的src /测试/ java目录,然后通过preSS F5 和运行Maven刷新您的项目 - >更新项目(右键项目,选择Maven的 - >更新项目...),这应该可以解决缺少必要的源文件夹:SRC /测试/ java的错误

There are several ways to fix it, the easiest is manually create src/test/java directory in the file system, then refresh your project by press F5 and run Maven -> Update Project (Right click project, choose Maven -> Update Project...), this should fix the missing required source folder: 'src/test/java' error.