Duplicate src packages when importing an existing project in Eclipse - java

When I try to import an existing project into eclipse,
I see duplicate packages for src folder(highlighted in red below)
Not sure why.How do i fix this?

This is not an issue, actually It's fine.
Eclipse displays the package view (as you pointed in the first red square) and also the directories inside your project (the second square).
As you can see in your screenshot, the first 3 folders contain the package icon (that's because you are using the Package Explorer view), then below your Maven dependencies you can find the physical folders.
If you don't want to see your package folder you may consider using Navigator view instead of Package Explorer.
Btw, you can configure filters for your view by using:
Then select the filter you consider appropiated.

Related

Eclipse showing java project src folder view as all packages and subpackages

Not sure how to really ask this question since I don't know what everything is called but I'll try to do the best I can.
So as I was cleaning up my classes. I right clicked my project and selected refresh. Then all of a sudden my project view changed, the src folder shows everything as packages and '.' separated subpackages. And all my code package declarations seems now to be undiscoverable.
I've attached a photo, hopefully you can petter understand this...How can I fix this to have the correct directory view/structure.
Edit:
Here is what I have linked to my JAVA build path
I don't understand what is happening? How can all of a sudden my project screw up like it has? Any help will be much appreciated
Look at the 'Java Build Path' in the project 'Properties' and check that you have the correct 'Source' folders. It looks like you may have just 'src' as a source folder when you should have 'src/main/java', 'src/test/java'...
I was able to fix this by maven>update project, then just refresh...
In addition to the previous answer you also may use empty package filter:
At the top-right of the Package Explorer view, there's a downward-pointing triangle. If you hover your mouse pointer over it you'll see View Menu.
Click the View Menu, select Filters, put a check next to Empty Packages, then click OK.
Same way you could tune other options for Package explorer such as file types to show etc.
Well, it seems pretty clear that your hierarchy does not match the name of your package, so just fix your hierarchy. It will be easier if you switch to the hierarchical view of the packages. To do so, go to Package explorer, View menu (arrow icon pointing to the bottom), Package presentation, Hierarchical.
The following worked for me:
Right Click on src (which is shown like empty package in my project) -> Build Path -> Use As Source Folder

Eclipse doesn't see class/package in import

I use eclipse.
my problem description:
In import I see red underlyed strings. But if I navigate - I see source code.
How does it dispay?
How can I fix it?
You must adjust the project's build path, so it contains the missing packages.
Long answer
You may navigate every class that is known to the workspace. But if they are underlined it means they are not available when building the project.
Click on the node "Referenced Libraries" to see what's included. If your imported package JAR is not listed there, adjust the build path.
Right-click on the folder containing "com/epam/dentsply/service" and choose "Build Path/Use as Source Folder". Be sure to select the one directly containing the "com" directory with your java files.

How to add prefix to package names?

I've got 45 java packages I've imported into a src folder in Eclipse. Each of course has a particular name, and contains numerous java files. Problem is that the import statements in the packages' classes all refer to the various packages (including themselves in the package line) with an initial prefix name.
So for example, if the package name is
snowman.image
the java files within start with abc.snowman.image
and refer to another package named snowball.hit as abc.snowball.hit. Needless to say, Eclipse complains that these packages referred to in the code do not exist.
I'm thinking I must've done something wrong. Did I import the packages incorrectly? Can I change some property so that the prefix is understood before the packages' names. I'd rather not go through hundreds of java files and manually change the package and import names.
First you need to make sure that the project configuration is correct. Right click on the project, then go to "properties", and in the tree on the left select "java build path". Switch to the "source" tab and and make sure then you have the "your project/src" as a source folder. Starting from the "src" folder you will have the package names just as Tom commented on your question.
Also eclipse has some nice feature, such as "organize imports" - default shortcut ctrl+shift+o - which will look through your source files and update your imports. This works both in the text editor for the current class, as also from the "navigator/package explorer" view for the entire. selected project.
Please make a backup of your project before trying this, as it will automatically change your files by removing unused and adding the imports it finds in your current structure so you might end up with snowball.hit instead of your desired abc.snowball.hit.

Ignore folders beginning with dot in IntelliJ

In project I work on there are folders with name started with dot sign. They are used by external tool to generate actual code/properties variation based on some properties. IntelliJ complains about java classes in these folders (path doesn't correspond to package name). What I'd like to do is to force the compiler to ignore specific folders (they shouldn't be used in build anyway). I found Settings->Compiler->Excludes option but I can't see the dot started folders when I try to specify exclusions. Pasting folder path doesn't work either. Not sure if it is like that because of Intellij or mac hidden folder issue. Any hints?
In the module editor, set the folder to be excluded from the project, i.e totally ignored. Select the folder and then click on the "Excluded" button. Then the folder will be shown in red and will not even show up in IDEA project view, and no indexing or compiling will take place on this folder.
You can "Show Hidden Files and Directories" which should be the last icon in the Select Path window.

Eclipse WTP: "The import ___ cannot be resolved for" error in a JSP file for a class defined in project

A Visual Studio user struggling w/ Eclipse...
I imported a set of servlets/JSPs into a project in Oracle Workshop for Weblogic. /page.jsp has the following import statement:
import="com.foo.bar.*"
Eclipse is displaying an error:
The import com cannot be resolved.
The class that implements the above import is in /WEB-INF/src but I don't know how to build the class in Eclipse to resolve that error. I assumed Eclipse would automagically build the .java file and place the output in /WEB-INF/classes, but it's not doing that.
It could be that I haven't structured my project directories correctly so perhaps that's why Eclipse isn't building my source. Any suggestions? How can I get this to work?
First of all, /WEB-INF/src is a rather strange place to keep your java sources; you may want to move them out of /WEB-INF (into /src in project root, for example)
Either way, you need to tell Eclipse where your sources are and where you want classes built to. It's done in project properties dialog:
Right-click on your project in Eclipse, select Properties
Click on Java Build path on the left
Click source tab on the right
Click Add Folder button and add your source folder (/WEB-INF/src or wherever you moved it to)
Ensure Allow output folders for source folders is checked below
Under newly added source path select output folder and point it to /WEB-INF/classes or other location of your choice.

Categories