0

I've got 45 java packages I've imported into a src folder in Eclipse. Each of course has a particular name, and contains numerous java files. Problem is that the import statements in the packages' classes all refer to the various packages (including themselves in the package line) with an initial prefix name.

So for example, if the package name is snowman.image the java files within start with abc.snowman.image and refer to another package named snowball.hit as abc.snowball.hit. Needless to say, Eclipse complains that these packages referred to in the code do not exist.

I'm thinking I must've done something wrong. Did I import the packages incorrectly? Can I change some property so that the prefix is understood before the packages' names. I'd rather not go through hundreds of java files and manually change the package and import names.

JohnK
  • 6,865
  • 8
  • 49
  • 75
  • 2
    The directories in your `src` folder must mirror your package names. The files with `package abc.snowman.image` must be in `src/abc/snowman/image`. The exact path depends on your project structure but the part starting from `abc` is a given – toniedzwiedz Jun 15 '12 at 09:28

1 Answers1

1

First you need to make sure that the project configuration is correct. Right click on the project, then go to "properties", and in the tree on the left select "java build path". Switch to the "source" tab and and make sure then you have the "your project/src" as a source folder. Starting from the "src" folder you will have the package names just as Tom commented on your question.

Also eclipse has some nice feature, such as "organize imports" - default shortcut ctrl+shift+o - which will look through your source files and update your imports. This works both in the text editor for the current class, as also from the "navigator/package explorer" view for the entire. selected project.

Please make a backup of your project before trying this, as it will automatically change your files by removing unused and adding the imports it finds in your current structure so you might end up with snowball.hit instead of your desired abc.snowball.hit.

Morfic
  • 15,178
  • 3
  • 51
  • 61
  • Thanks, Grove, this is very helpful. I did as you recommended and of the packages I've sampled, it worked (still need to import other packages--Apache, et al.--to clear all errors though). I really appreciate your help! – JohnK Jun 15 '12 at 14:27
  • Glad to be of assistance, happy coding :) – Morfic Jun 15 '12 at 17:17
  • 2
    Oh, and BTW, if you didn't already know, you could use Maven (http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html) for dependency management (Apache, et al) and other tasks such as compiling and building your application. – Morfic Jun 15 '12 at 17:24