简体   繁体   中英

How do you create a 'java' directory under the auto-generated 'src' directory in Eclipse?

I have create a project under eclipse. Eclipse automatically creates a directory named 'src'. The Source control system I am using imposes a directory structure which begins src/java/com/company_name/package_name/java_class_name.java .Other packages which are dependent ie use the java files in other eclipse projects refer to the classes with import com.company_name.package_name.java_class_name.

My question is in order for the above to work I need to create a 'java' directory under the autogenerated 'src' and link this to the directory where my files are starting 'com'. If I select "project-properties-Java Build Path-Add Folder-link source" then specify my directory structure 'src/java' it creates a java directory at the same level as my src directory. If I select add folder it presents me with existing folders only which don't include 'java'. I cannot see a way to resolve this.

Right click on the src folder and select New / Other... / Folder (not Source Folder). Type the name 'java' into the dialog then click OK.

But, that's not what you want. What you really want is to remove the source folder 'src' then add a new source folder 'src/java'. This is so that the package names are 'com.blah...' and not 'java.com.blah...'.

So, first delete the src folder.

  1. right click on src
  2. select Delete
  3. confirm

Next, create a new source folder.

  1. Right click on the project
  2. select New / Source Folder
  3. type in 'src/java' (no quotes)
  4. click OK

Now you have a new source folder with the proper path, and the package names will all be as expected in Eclipse.

Modified alternative to Zagrev's answer:

You still need to delete the src directory from Eclipse project

Manually create the Java subdirectory.

Then use Build Path-> Link Source... and link it to the created directory.

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