Folders mess up after import project into Eclipse - java

I have a JAVA project contains multiple folders, and after I imported them into Eclipse, the folders messed up like below.
How can I put these "src/main/java" folders under the "src" one in eclipse, these folders are well-organized on my file system.

eclipse detects project type and it adds directory structure in .classpath and .project when you import new project,
if you want to see raw structure, switch to navigator view
windows > show view > navigator

Related

How can I import this java project with no src folder into eclipse?

How can I import the java project shown in the picture below into eclipse, since there is no src folder in it.
Eclipse doesn't depend on source folders being called 'src'. You can import any directory as a "project" in eclipse and then configure the source folders from the right click -> properties -> java build path.
However, if that directory doesn't actually contain any source code, the question is if you're trying to use the classes/jars contained within. Then you need to add those classes/jars to your classpath.

Eclipse won't update after adding project to workspace folder

I added a Java project (containing one default package with 2 classes) to my folder which I declare as my workspace in Eclipse. But when I launch Eclipse, it does not add this project in the package explorer. What can I do to solve this problem?
You can't copy files or folders to your workspace folder, you have to import the project into Eclipse:
From the main menu bar, select command link File > Import.... The Import wizard opens.
Select General > Existing Project into Workspace and click Next.
Choose either Select root directory or Select archive file and click the associated Browse to locate the directory or file containing the projects.
Under Projects select the project or projects which you would like to import.
Click Finish to start the import.
Click with right button on the folder containing sources and select use as source folder

Eclipse Package Explorer not matching physical folder structure

Newbie question
I have downloaded a project from git repository using Eclipse (Import-> Clone URI).
It created a folder in my local MyDocuments git folder and I can also see the project in the Eclipse's Package Explorer.
For some reason, for any source file, say HelloWorld.java which I see inside the MyDocuments git project folder, I do not see HelloWorld.java in Eclipse's package explorer. I have changed perspective to java/javaee/java browsing etc.
Is there some setting/perspective in Eclipse where I can see all the source files?
After successful cloning git repository inside eclipse, you need to import these project inside eclipse.
Click Windows > Show view > Other then select Git repositories view. Right click on Working directory then select Import project.

Wrong package name when using automatically added imports in Eclipse

I have several Maven projects converted into one Eclipse workspace. When I edit the code under Eclipse, I sometimes use CTRL+SHIFT+M combination of keys to automatically add imports to the classes from a project in my workspace. But somehow they are added like this:
import src.main.java.com.mycompany;
while to real package I wanted to import is com.mycompany.
This has to be some configuration in Eclipse to fix this but I'm confused. However, this issue is very annoying.
EDIT:
I've forgotten to mention that Eclipse files were generated using mvn eclipse:eclipse command.
Under Eclipse project seems to be configured properly. Its source folders set like this:
src/test/java
src/test/resources
src/main/java
src/main/resources
And everything under Eclipse works properly except the situation when I press CTRL+SHIFT+M keys
The standard source folder for Java projects is
./src
For imported maven projects, simply remove this folder from the list of source folders at the build path settigs. The correct source folder is
./src/main/java
In eclipse;
Remove the existing source folders first.
-right click -> menu -> build path -> remove from build path
then
Right click on the source folder.
build path -> use as source folder.
Seems like your settings are pointing to the parent of the source folder so src is recognized as package by eclipse.
It's because eclipse is not aware of the convention over configuration filestructure Maven is following. Install the M2Eclipse plugin and File > New > Other > Maven Project for new projects or for existing ones right click on your imported project on Package Explorer > Maven > Enable Dependency Management. Once successfully done, on the Package Explorer you would see your project nicely gathered following the Maven conventonal filestructure like src/main/java, src/main/resources, src/test/java and from then on you'll start seeing your package structure hierarchy like com.mysite.myproject..
First remove it. Then add it back using right click on package->build path->configure build path-> Source->Add Folder and add the entire /src/main/java tree
You've got the wrong source folders in your build path, and it's a wonder that anything works at all.
You can use either the maven-eclipse-plugin or M2Eclipse to automate getting this right, or you can manually fix the build path to call our your actual source folders, not their great-grandparents.
Non of the above worked for me. Finally I just changed the name of the scr folder to scr-java and this removed the package structure with scr as root package.

Importing projects with Eclipse so new stuff I add will go to the source directory as well

When I do File -> Import, General (from the pop-up window)->Existing Projects into Workspace, I can browse to where all my projects are and import them so my Eclipse workspace folder with its .metadata is in a separate location from my source directory.
The problem is, if I add a new project or even add a new file within an existent project, the new files get made in my Eclipse workspace folder, not over where the other code lives.
How do I tell Eclipse to put new code in the source directory, not in the workspace directory? When importing, I did not check the checkboxes "Copy projects into workspace" or "Add project to working sets" (Add project to working sets requires the selection of working sets, which I don't know about).
It depends on the kind of project you are creating. For example, a "Project" type project that just contains dumb files lets you uncheck the "Use default location" option and will actually be created in whatever directory you give it.
Java projects, on the other hand force you to create them in the workspace.
For project types that eclipse will only create in the workspace you can use the following workaround.
Create the project in your workspace.
Delete the project from eclipse without deleting the files on disk.
Use your OS tools to move the project folder where you want it.
Back in eclipse: File -> Import -> Existing Projects into Workspace
Browse to folder containing your relocated project.
Make sure to uncheck the "Copy projects into workspace" option

Categories

Resources