Adding folder in eclipse in src directory without making it package

后端 未结 5 1470
盖世英雄少女心
盖世英雄少女心 2020-12-24 02:13

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

5条回答
  •  旧时难觅i
    2020-12-24 02:29

    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.

提交回复
热议问题