While creating one folder in src directory in one project in eclipse, it makes that folder a package. Is there any way to avoid this folder from automatically being a packag
When you run a Java project in eclipse, the current working directory is the root folder of the project. So why not just create your resource folder there?
ProjectDirectory
../bin
../src
../resourceDirectory
Then, in your project, you can fetch resourceDirectory
with
public File getDirectory(String dir) {
File cwdir = new File(".").getParentFile(); // remove the "." in path
for (File f : cwdir.listFiles()) {
if (f.isDirectory() && f.getName().equals(dir)) {
return f;
}
}
return null;
}
and
File resourceDir = getDirectory("resourceDirectory");
if (null == resourceDir) {
System.err.println("Resource directory not found");
System.exit(-1);
}
Note : you might perhaps want to create an utility class for the getDirectory()
method, or something similar. This is just an example.
Bottom line is that the application will most likely be launched where it should be and you might just use a startup file (.bat, .sh, etc.) to do that anyway. There is no need of putting resource directories inside your source or binary folder; keep them separated.
Eclipse forces you distinguish between source directories and ordinary folders. Any subdirectories in a source folder will be considered a package.
In your case, you can create an ordinary folder outside of src/
to prevent the subdirectories from being interpreted as packages.
Alternatively, you can modify the project properties to have src/
be considered an ordinary directory, and put a source directory within it.
You can manage which directories in a project are considered source directories by:
Properties
.Java Build Path
. In the right pane, select the Source tab
.Any folder in src directory becomes a package. If you wish to have a main folder then create a source folder of name main and then create the required package in main folder.
I added the "Excluded" pattern with value ** to 'Java Build Path -> Source - > src/main/resources' and my package became a simple folder in Eclipse.
You need to go to Project -> Properties -> Java Build Path -> Source (tab).
Remove src
from "Source Folders on Build Path"
Then add src/main
as a source folder. If you already have org
under main, then your packages should start with org
as desired.