Eclipse: The declared package does not match the expected package

后端 未结 13 469
挽巷
挽巷 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:41

    The build path should contain the path 'till before' that of the package name.

    For eg, if the folder structure is: src/main/java/com/example/dao If the class containing the import statement'package com.example.dao' complains of the incorrect package error, then, the build path should include:src/main/java This should solve the issue.

    0 讨论(0)
  • 2020-12-25 09:43

    Just go into the build path and change the source path to be src/prefix1 instead of src.

    It may be easiest to right-click on the src directory and select "Build Path / Remove from build path", then find the src/prefix1 directory, right-click it and select "Build Path / Use as source folder".

    0 讨论(0)
  • 2020-12-25 09:44

    I happened to have the same problem just now. However, the first few answers don't work for me.I propose a solution:change the .classpath file.For example,you can define the classpathentry node's path like this: path="src/prefix1/java" or path="src/prefix1/resources". Hope it can help.

    0 讨论(0)
  • 2020-12-25 09:52

    Happens for me after failed builds run outside of the IDE. If cleaning your workspace doesn't work, try: 1) Delete all projects 2) Close and restart STS/eclipse, 3) Re-import the projects

    0 讨论(0)
  • 2020-12-25 09:52
    1. Right click on the external folder which is having package
    src.prefix1.prefix.packagename1 
    src.prefix1.prefix.packagename2
    
    1. Click Build path --> Remove from build path.

    2. Now go the folder prefix1 in the folder section of your project.

    3. Right click on it --> Build path --> Use as source folder.

    4. Done. The package folder wont show any error now. If it still shows, just restart the project.

    0 讨论(0)
  • 2020-12-25 09:53

    If you have imported an existing project, then just remove your source folders and then add them again to build path, and restart eclipse. Most of the times eclipse will keep showing the error till you restart.

    0 讨论(0)
提交回复
热议问题