Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eclipse does not like it if a package exists in parallel directory structure..

 
Jean Robillard
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have the following directory structure w/ JUNIT (which is not really relevant though)

src (directory)
src/com
src/com/xyz
src/com/xyz/SomeClass.java

test (directory)
test/com
test/com/xyz
test/com/xyz/SomeClassTest.java

Note: src, test are under the same project's "Java Resources" node in Eclipse.


Unfortunately, within Eclipse, SomeClassTest cannot test SomeClass, because it cannot "see" SomeClass even though they are supposed to be in the same package com.xyz. Eclipse would simply complain that SomeClass cannot be resolved, with an "X" icon at the offending line that references SomeClass within SomeClassTest.

Can I resolve this issue in Eclipse, or do I have to do this manually (e.g. via ANT) by copying these files into the same directory before compiling them together (which means, I wouldn't be able to use Eclipse anymore). Thanks....
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are both "src" and "test" marked as Java source files within Eclipse?

Did you by any chance get this directory structure form a Maven archetype? If so, running "maven eclipse:eclipse" will create an Eclipse project with the proper source folder already marked.
 
Jean Robillard
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I am not using Maven. But it's resolved now. For some reason, I must go to Project->Properties->Source tab->Add Folder... menu to add a new source folder. Instead, I had manually created a folder called test from Windows explorer. Even though Eclipse detected this directory and displayed it under "Java Resources" in its Project Explorer, it didn't quite do it right and exhibited the problem I originally described, even though the Project properties correctly displayed it as a source folder. Weird.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18009
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jean Robillard wrote:No I am not using Maven. But it's resolved now. For some reason, I must go to Project->Properties->Source tab->Add Folder... menu to add a new source folder. Instead, I had manually created a folder called test from Windows explorer. Even though Eclipse detected this directory and displayed it under "Java Resources" in its Project Explorer, it didn't quite do it right and exhibited the problem I originally described, even though the Project properties correctly displayed it as a source folder. Weird.


There's folders and then there's SOURCE folders. If you'll notice in the Navigator view, the two have slightly different icons. Only SOURCE folders are processed by the Eclipse compiler.

Once compiled, the output classes are written to a binary folder. By default, only one such folder exists per project, but you can make a separate binary folder for any or all of the source folders - for example, a test/classes directory.

The binary folder(s) are referenced as part of the classpath for both compiling and testing.
 
santoshkumar savadatti
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:

There's folders and then there's SOURCE folders. If you'll notice in the Navigator view, the two have slightly different icons. Only SOURCE folders are processed by the Eclipse compiler.



old post helped me out. thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic