0

Let assume I have such class:

package com.stackoverflow.hierarchy;

class A {}

that is located in ~/MyProject/src/com/hierarchy

Is that possible to avoid compilation errors in IDE for A-class (like *The declared package "com.stackoverflow.hierarchy" does not match the expected package "com.hierarchy"*)

I've tried to search some answer in Java Build Path properties Project Properties. But I failed. Maybe some body can help with this staff?

Ken Chan
  • 84,777
  • 26
  • 143
  • 172
Michael Z
  • 3,883
  • 10
  • 43
  • 57
  • Can you explain _why_ you want to do this? – Gray Nov 30 '11 at 13:58
  • @Gray Well... I have dynamically developed project that was ported from .NET to Java. So some things are go wrong with Java best practices. Project is compiled fine with Ant. But I would like to run my tests through Eclipse so I need it be compiled in Eclipse too. – Michael Z Nov 30 '11 at 18:16
  • Any reason to not have Eclipse correct the packages for you? Is there a problem with putting them into the right directory hierarchy? – Gray Nov 30 '11 at 18:54
  • @Gray >Any reason to not have Eclipse correct the packages for you?< Sorry don't understand here. >Is there a problem with putting them into the right directory hierarchy< Yes! If I'll put them in the right directory I'll get inconsistency with SVN. – Michael Z Dec 01 '11 at 07:45
  • Eclipse can correct the packages of the files in question if you let it and if you have subclipse installed, they will be moved in SVN as well. – Gray Dec 01 '11 at 13:19
  • @Gray The point is - I don't need(that is forbidden) to move that packages on SVN! – Michael Z Dec 01 '11 at 18:50
  • `svn move` is forbidden? Huh, ok. That's unfortunate. Best of luck. – Gray Dec 01 '11 at 18:53

1 Answers1

0

It is the Java problem but not the eclipse problem.

From 7.2.1 Storing Packages in a File System in The Java Language Specification:

Under this simple organization of packages, an implementation of the Java platform would transform a package name into a pathname by concatenating the components of the package name, placing a file name separator (directory indicator) between adjacent components.

For example, if this simple organization were used on a UNIX system, where the file name separator is /, the package name:

jag.scrabble.board

would be transformed into the directory name:

jag/scrabble/board

and:

com.sun.sunsoft.DOE

would be transformed to the directory name:

com/sun/sunsoft/DOE

Your packages name should match the file pathname .So you should change Class A 's package from package com.stackoverflow.hierarchy to package com.hierarchy

or put the Class A into the folder /MyProject/src/com/stackoverflow/hierarchy

Ken Chan
  • 84,777
  • 26
  • 143
  • 172