49

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:

Project 'xxx-1.0-SNAPSHOT' is missing required source folder: '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:

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?

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

4
  • 1
    This is not an m2e-android issue, version 1.1 of the m2e plug-in now requires that you have a src/test/java folder. Could you please re-edit so as not to confuse people. Aug 16, 2012 at 7:43
  • Apologies, turns out this was an error with m2e-android. Sep 3, 2012 at 13:18
  • Just create a plan folder named src/test/java. The pixie dust has already been applied. May 24, 2013 at 11:24
  • Ah, so if I create a plain src/test/java folder, the package folder appears in addition?
    – nsandersen
    Nov 9, 2016 at 12:01

10 Answers 10

92

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).

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>

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:

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 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.

4
  • Thanks, I will try that when I'm at home tonight. Is there actually no way to tell the android archetype to generate src/test/java?
    – Bevor
    Aug 16, 2012 at 6:30
  • 2
    There is an open ticket to add this folder to the Android archetypes project: github.com/akquinet/android-archetypes/issues/34 Aug 16, 2012 at 7:42
  • Execute the following in the root dir: mkdir -p src/{main,test}/{java,resources} then press ALT + F5 May 3, 2016 at 11:16
  • 11
    This... This must be joke. I'm sure this font is a joke. Jan 18, 2018 at 23:26
18

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

It works fine.

1
  • 2
    In the build path --> Source, my src/test/java was marked as missing. So I removed the folder and created a new one with the same name. This worked for me.
    – ruhong
    Nov 22, 2016 at 13:07
7

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 .

2
  • 2
    This worked for me. What a ridiculous problem to have release after release. Dec 27, 2013 at 17:59
  • this is awesome! @wejack
    – Raman
    Nov 5, 2020 at 9:51
2

This is possibly caused due to lost source directory.

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

2

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.

1

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

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/

1

In the case of Maven project

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

0
0

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

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

0

Select project -> New -> Folder (not source folder) -> Select the project again -> Enter the folder name as (src/test/java) -> finish. That's it.

If the test source is missing, it would link it automatically. If not, then require to link it manually.

0

Fixing this issue is really very simple, Just Right Click on the project go to Properties. After that go to Build Path, You see an error like ” 2 build path entries are missing “ This error usually comes when the JRE System Library is wrongly pointed. Now go to the Libraries tab and change the JRE System Library to the correct version by clicking on Edit.

Here is the complete Tutorial: https://kkjavatutorials.com/how-to-fix-missing-src-main-java-src-test-java-folders-in-the-eclipse-maven-web-project/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.