Eclipse: The declared package does not match the expected package

后端 未结 13 606
挽巷
挽巷 2020-12-25 09:03

I have a problem importing an external project. I go File -> Import... -> Existing Projects into Workspace, choose the folder where the project is located and everything is

13条回答
  •  南笙
    南笙 (楼主)
    2020-12-25 09:57

    Suppose your project has a package like package name1.name2.name3.name4 (declared package)

    Your package explorer shows
    package top level named name1.name2
    sub packages named name3.name4

    You will have errors because Eclipse extracts the package name from the file directory structure on disk starting at the point you import from.

    My case was a bit more involved, perhaps because I was using a symbolic link to a folder outside my workspace.

    I first tried Build Path.Java Build Path.Source Tab.Link Source Button.Browse to the folder before name1 in your package.Folder-name as you like (i think). But had issues.

    Then I removed the folder from the build path and tried File > Import... > General > File System > click Next > From Directory > Browse... to folder above name1 > click Advanced button > check Create links in workspace > click Finish button.

提交回复
热议问题