Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem in packages in importing in Eclipse

Tags:

java

eclipse

I am trying to import some existing projects into Eclipse. The structures for their packages is:

Project/
        /src
          /java
             /a
              /b
                /c

Once imported in the package explorer I see:

Project
  src/java
       --a
         --b
            --c
               - AClass.java

This is ok, since the classes e.g. AClass.java are defined in package: a.b.c But in one project the structure (once imported) becomes:

Project
  src
     --java
        --a
          --b
            --c
              - AClass.java

And that causes the error that AClass.java is defined to be in package a.b.c but it is actually under java.a.b.c
Why is this happening? Why in this specific project java is not ignored as part of package?
Thanks

like image 329
Cratylus Avatar asked Jan 11 '11 07:01

Cratylus


People also ask

How do I fix a package error in Eclipse?

Go to src folder of the project and copy all the code from it to some temporary location and build the project. And now copy the actual code from temporary location to project src. And run the build again. Problem will be resolved.

Why Import option is not working in Eclipse?

Go to Preferences » Java » Editor » Content Assist » Advanced. Make sure Other Java Proposals is ticked/checked. If that does not work simply close the project and reopen it.

How do I fix all imports in Eclipse?

Go to the line of unused import, press Ctrl + 1, which is an Eclipse shortcut of a quick fix. This will show a drop-down menu to fix this error and one of them will be “remove unused imports.” It will remove that import statement from the Java file.


1 Answers

How are you creating the Eclipse projects? It sounds like you just need to put "java" as a root on on the source path here, instead of "src". You can do this by editing the build path after the import process, of course.

like image 72
Jon Skeet Avatar answered Oct 06 '22 14:10

Jon Skeet