如何处理 Android/Maven 项目中缺少 src/test/java 源文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11976223/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:20:25  来源:igfitidea点击:

How to deal with missing src/test/java source folder in Android/Maven project?

androideclipsemavenm2eclipsem2e

提问by Bevor

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

我对 Maven 与 Android 结合还不是很有经验,所以我按照这些说明制作了一个新的 Android 项目。创建项目后,我收到以下错误消息:

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

项目“xxx-1.0-SNAPSHOT”缺少所需的源文件夹:“src/test/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:

当我尝试使用 New->Other->Java-Source Folder with src/test/java 添加新的源文件夹时,我收到另一条错误消息:

The folder is already a source folder.

该文件夹已经是一个源文件夹。

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?

但是我的项目中没有任何 src/test/java 文件夹。我该如何处理?设置项目的干净方法是什么,因为我认为此说明中缺少某些内容。那么Maven的方式是什么让src/test/java出现呢?

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

我正在使用 Eclipse Juno、m2e 1.1.0、m2e 0.4.2 的 Android 配置。

回答by yorkw

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-android 插件升级(版本 0.4.2)以来,我也意识到了这个烦人的事情,它发生在新项目创建和现有项目导入中(如果你不使用 src/test/java)。

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

看起来 m2e-android(或者可能是 m2e)现在总是试图添加src/test/java为源文件夹,无论它是否确实存在于您的项目目录中,在 .classpath 文件中:

<classpathentry kind="src" output="bin/classes" path="src/test/java">
  <attributes>
    <attribute name="maven.pomderived" value="true"/>
  </attributes>
</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:

由于它已经添加到项目元数据文件中,所以如果您尝试通过 Eclipse 添加源文件夹,Eclipse 会抱怨 classpathentry 已经存在:

enter image description here

在此处输入图片说明

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 F5and run Maven -> Update Project (Right click project, choose Maven -> Update Project...), this should fix the missing required source folder: 'src/test/java' error.

有几种方法可以修复它,最简单的方法是在文件系统中手动创建 src/test/java 目录,然后通过按下F5并运行 Maven -> Update Project(右键单击项目,选择 Maven -> Update Project.. .),这应该修复缺少的必需源文件夹:'src/test/java' 错误。

回答by Kandy

We can add java folder from

我们可以从

  1. Build Path -> Source.
  2. click on Add Folder.
  3. Select main as the container.
  4. click on Create Folder.
  5. Enter Folder name as java.
  6. Click on Finish
  1. 构建路径 -> 源
  2. 单击添加文件夹
  3. 选择 main 作为容器。
  4. 单击创建文件夹
  5. 输入文件夹名称为 java。
  6. 点击完成

It works fine.

它工作正常。

回答by weHyman

I solve the problem by creating a folder named "src/test/resources" first, then i rename the folder to "src/test/java" ,finally create a "src/test/resources" folder again .It works .

我通过首先创建一个名为“src/test/resources”的文件夹来解决这个问题,然后我将该文件夹重命名为“src/test/java”,最后再次创建一个“src/test/resources”文件夹。它有效。

回答by JavaCreeper

This is possibly caused due to lost source directory.

这可能是由于丢失了源目录造成的。

Right click on the folder src -> Change to Source Folder

右键单击文件夹 src -> 更改为源文件夹

回答by Mehdi

I had the same issue, fixed it. Create the missing folder directly in your file system (Using windows explorer for example) . And then, refresh your project under eclipse.

我遇到了同样的问题,已修复。直接在您的文件系统中创建丢失的文件夹(例如使用 Windows 资源管理器)。然后,在 eclipse 下刷新您的项目。

回答by Ricardo Gladwell

This is a bug in the Android Connector for M2E (m2e-android) that was recently fixed:

这是最近修复的 Android Connector for M2E (m2e-android) 中的一个错误:

https://github.com/rgladwell/m2e-android/commit/2b490f900153cd34fff1cec47fe5aeffabe44d87

https://github.com/rgladwell/m2e-android/commit/2b490f900153cd34fff1cec47fe5aeffabe44d87

This fix has been merged and will be available with the next release. In the meantime you can test the new fix by installing from the following update site:

此修复程序已合并,将在下一个版本中提供。同时,您可以通过从以下更新站点安装来测试新修复:

http://rgladwell.github.com/m2e-android/updates/master/

http://rgladwell.github.com/m2e-android/updates/master/

回答by Dish

Removing the m2 plugin from startup-up plugin's list and doing a Maven->Update Projects on all the projects worked for me.

从启动插件列表中删除 m2 插件,并对所有对我有用的项目执行 Maven->Update Projects。

Note** One should not create additional folders to avoid merging them while using SVN/Git based branches.

注意** 在使用基于 SVN/Git 的分支时,不应创建额外的文件夹以避免合并它们。

回答by ahmednabil88

In the case of Mavenproject

Maven项目 的情况下

Try right click on the project then select Maven -> Update Project...then Ok

尝试在该项目右键单击,然后选择Maven -> Update Project...Ok