74

How do I create the src/main/java and src/test/java in my default web application project in Eclipse without Maven? My current folder structure is

TestApp
├── JavaResources
│   └── src  
│       └── com.mypackage
└── WebContent
Bitswazsky
  • 4,242
  • 3
  • 29
  • 58
Sandeep Rao
  • 1,749
  • 6
  • 23
  • 41

9 Answers9

185

As you've discovered, you can't have a source folder inside another source folder, so before you can create src/main/java you have to tell Eclipse not to treat src as a source folder. To do this, right click on the src folder and select build path -> remove from build path.

Once you have done this src will appear in the folder tree in its normal place, so you can create the main and java folders under it, and move the existing src/com to src/main/java/com. Finally right-click the newly-created java folder and select build path -> use as source folder.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
  • After selecting use as source folder option, the structure of folder is created but while updating the maven project it is giving error : Unable to update maven configuration for the following projects. Cannot nest 'Foldername/src/main/java' inside 'Foldername/src'. To enable the nesting exclude 'main/' from 'SelectExample/src' – S Kumar Mar 18 '18 at 18:07
12

I have solved this issue by below steps:

Right click the Maven Project -> Build Path -> Configure Build Path In Order and Export tab, you can see the message like '2 build path entries are missing' Now select 'JRE System Library' and 'Maven Dependencies' checkbox Click OK

6

Open Properties > Java Build Path for the project. Select the Source tab and use Add Folders to add source folders.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Thanks for replying but when I try to add sub folders I am getting and error msg . "Cannot nest 'TestApp/src/main/java exclude 'main/' from 'TestApp/src" – Sandeep Rao Apr 07 '14 at 14:17
  • You simply cannot have `src` and `src/main` both as a source folder by default. But you can exclude `main` from `src` in `Source` tab (my Eclipse version did it by default)... – Betlista Apr 07 '14 at 14:21
  • Can you explain me how I can exclude it ? – Sandeep Rao Apr 07 '14 at 14:28
  • Remove the existing src entry and then add the new entries – greg-449 Apr 07 '14 at 14:32
2

Remove the actual source folder definition in the build path and add a new source folder an name it src/main/java

markusw
  • 1,975
  • 16
  • 28
  • I tried to edit and rename the folder structure but I am getting the following error.An internal error occurred during: "Setting build path". assertion failed: Cannot move '/TestApp/src'. Destination should not be under source's hierarchy. – Sandeep Rao Apr 07 '14 at 14:29
  • Do not edit it! just delete it and create a new one! – markusw Apr 07 '14 at 14:30
  • I already have some packages under src folder and I don't want to lose it. Nvm I was able to do it. Thanks! – Sandeep Rao Apr 07 '14 at 14:32
2

If the package structure is setup as src.main.java.com.inventica, instead of com.inventica, that’s usually because under project properties > Java build path > Source, the source folder is setup as src instead of src/main/java. There’s no easy way to fix this, so remove src as a source folder and click ok.

Now Eclipse will show a folder hierarchy src/main/java. Browse to the java folder > right-click > build path > use as source folder.

After this, you may have to fix the Eclipse .project and .classpath files to have it use Maven to manage dependencies, builds etc.

Typically, you can copy this from a working project since there isn’t anything project specific here assuming you’re structured as a standard Maven project.

Steffen Harbich
  • 2,639
  • 2
  • 37
  • 71
Puneet Lamba
  • 755
  • 8
  • 15
1

the problem will be solved by checking on 'JRE System Library' and 'Maven Dependencies' checkboxs Click OK. this is found in the project's 'build path option'

AmosJ
  • 11
  • 3
1

enter image description here

If you don't find the Included Path just add the path it will resolve.

1

Solution One:

Change the JRE version to 1.8 and change it back to the original version (for maven-archetype-webapp, the original version is 1.7).

Steps Here

Solution Two:

Check the JRE option and Maven Dependencies option in "Order and Export".

Steps Here

Himanshu Bansal
  • 2,003
  • 1
  • 23
  • 46
Little Bug
  • 109
  • 1
  • 4
0

Simple solution would be create 'java' folder directly one the drive into src/main even before opening it in eclipse that way eclipse will not complain about the issue.

Guru
  • 53
  • 1
  • 8