今天导入以前用过的项目后,所有的src目录下的java文件全部报错(The declared package does not match the expected package)。
在网上找了好久终于找到了解决方法(http://stackoverflow.com/questions/6997524/the-declared-package-does-not-match-the-expected-package):
Most likely what's wrong is that your project properties point to the wrong place in order for the classpath to work.
In order for Eclipse to separate your projects, you need a directory that contains the project. Then you should have a directory for source and output (although it'll work without it - it's very ugly that way though). Finally, your directories corresponding to your packages should be inside your source folder.
Suppose I'm writing "Bas.java" and it's inside the foo.bar package:
Source might look like this
<common dir>/basproject/src/java/foo/bar/Bas.java
Compiled code might look like this
<common dir>/basproject/bin/classes/foo/bar/Bas.class
Explanation:
<common dir> is the base directory where Eclipse looks for all java projects.
/basproject is where everything associated with the Bas project goes.
/src/java is a place to organize the Java source. I usually like "src/java" because then I have a natural place to put non-java stuff ("src/?") or unit tests ("src/tests").
/foo/bar obviously cooresponds to your package.
I think you get the picture...
Now then, having done that, I next have to set Eclipse up such that the package structure is used correctly.
* Right-click the project name in Eclipse and select Properties.
* Select "Java Build Path" in the left side of the pop-up window.
* Select the "Source" tab in the right side of the pop-up window.
* For my mythical example, I'd want to set the input to "basproject/src/java". Unfortunately it's not possible to edit the input folder shown. Your best bet is to create a new entry without removing the old one so you have a pattern.
* For my mythical example, I'd set the output to "basproject/bin/classes".
* For now, set "Included" to "All" and "Excluded" to none. Later you can use those to fine-tune unit tests and the like.
* Finally, once the structure looks the way you want, delete any entries that don't work.
That should do it.
解决方法:
1、选中项目右击选择Build Path-->再选择Configure Build Path;
2、选择“Source”标签,把“eheal”改为“eheal/src”,ok。
在网上找了好久终于找到了解决方法(http://stackoverflow.com/questions/6997524/the-declared-package-does-not-match-the-expected-package):
Most likely what's wrong is that your project properties point to the wrong place in order for the classpath to work.
In order for Eclipse to separate your projects, you need a directory that contains the project. Then you should have a directory for source and output (although it'll work without it - it's very ugly that way though). Finally, your directories corresponding to your packages should be inside your source folder.
Suppose I'm writing "Bas.java" and it's inside the foo.bar package:
Source might look like this
<common dir>/basproject/src/java/foo/bar/Bas.java
Compiled code might look like this
<common dir>/basproject/bin/classes/foo/bar/Bas.class
Explanation:
<common dir> is the base directory where Eclipse looks for all java projects.
/basproject is where everything associated with the Bas project goes.
/src/java is a place to organize the Java source. I usually like "src/java" because then I have a natural place to put non-java stuff ("src/?") or unit tests ("src/tests").
/foo/bar obviously cooresponds to your package.
I think you get the picture...
Now then, having done that, I next have to set Eclipse up such that the package structure is used correctly.
* Right-click the project name in Eclipse and select Properties.
* Select "Java Build Path" in the left side of the pop-up window.
* Select the "Source" tab in the right side of the pop-up window.
* For my mythical example, I'd want to set the input to "basproject/src/java". Unfortunately it's not possible to edit the input folder shown. Your best bet is to create a new entry without removing the old one so you have a pattern.
* For my mythical example, I'd set the output to "basproject/bin/classes".
* For now, set "Included" to "All" and "Excluded" to none. Later you can use those to fine-tune unit tests and the like.
* Finally, once the structure looks the way you want, delete any entries that don't work.
That should do it.
解决方法:
1、选中项目右击选择Build Path-->再选择Configure Build Path;
2、选择“Source”标签,把“eheal”改为“eheal/src”,ok。