0

Every Java project I download has main and test folders. Both contain java and resources sub-folders. Some projects even add more levels: for instance dir1, dir2, dir3 and etc in the root, where each dirX contains src with main and test subfolders. How do I handle them? If I just drop the content of the project root into the default src, Eclipse will attribute classes into dirX.src.main.java.com.pkgY obviously resulting in "The declared package com.pkgY does not match the expected package dirX.src.main.java.com.pkgY" error. Am I supposed to add every dirX/src/java directory as a source separately in buildpath, as this answer suggests? What about the corresponding tests? Thanks.

Community
  • 1
  • 1
Val
  • 1
  • 8
  • 40
  • 64

2 Answers2

0

This structure is Maven's Standard Directory Layout. In your case, you need to add both src/main/java and src/test/java (right click on java folder and go for use this as source folder) and resources as well to classpath through configure buildpath option. Refer this maven link for more details on this.

RP-
  • 5,827
  • 2
  • 27
  • 46
0

Make sure you installed m2e (http://download.eclipse.org/technology/m2e/releases), and if you're doing JavaEE stuff with Eclipse WTP, you should also probably add m2eclipse-wtp (https://github.com/sonatype/m2eclipse-wtp/wiki)

Then, you have 2 solutions :

  • either right click on each project and Configure > Convert to Maven project
  • remove the projects from your workspace and do an "Import as existing maven project"

m2e will take care of configuring Eclipse based on your pom.xml configuration.

Fred Bricon
  • 5,369
  • 1
  • 31
  • 45