简体   繁体   中英

Eclipse, Java project - How do I add a source folder where the folder name is part of the package name?

I tried searching for the answer and got a lot of similar problems but not this exact issue.

I'm trying to set up Eclipse from a CVS project that has a non-Eclipse-friendly folder structure.

Inside the project folder, all the source code is under a folder named "com." Subsequently, all the import statements inside the source files are in form of:

import com.xxx.yyy.SomeObject;

Which, of course, refers to SomeObject.java located at com/xxx/yyy.

The problem is when I add the com folder inside Properties -> Java Build Path -> Source tab -> Add Folder, Eclipse complains about the import statement above. It says, "The declared package 'com.xxx.yyy' does not match the expected package 'xxx.yyy'".

How do I solve this?

My recommendation, especially if your source files are all in one - or just a few - director(ies):

1) Check out your CVS project into a temp folder

2) Create a new Eclipse project from scratch. It will create a "src" folder by default.

3) Create your package with Eclipse. It will automatically create subfolders representing your package name (eg com.foo.mypackage).

4) Drag/drop your source into the Eclipse package

5) Make sure everything builds

6) Save the new Eclipse folder tree to CVS (ideally, use the CVS plugin for Eclipse to do this).

IMHO...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM