Eclipse project structure showing improper project structure - java

I have set up an eclipse workspace. Inside this workspace i have a dynamic web app cloned from repository. My working directory looks like following.
I am seeing a different hierarchy in Eclipse project explorer. My project explorer looks like following.
Ideally it should show src, WebContent, build.xml etc. inside java resources but it shows entire project folder inside java resources.
Troubleshooting I tried:
1. Delete existing project from project explorer and import the project again.
2. Pull the changes in local copy and refresh the project from project explorer.
3. Change the working directory and import a new project.
None of this seemed to resolve the problem.
Appreciate if someone could help me with the root cause and a solution to this.

Related

How do I build and run an existing project in Eclipse?

I would like to start the program from this repository: https://github.com/SaifurRahmanMohsin/Personal-Diary but when I dowload it and open the project in Eclipse I am not able to build/compile it. So i also can't run it.
Do I have to change run configurations or build a working set or something like that? I usually don't work with Eclipse so I am a bit overwhelmed.
screenshot eclipse1
screenshot eclipse2
Check out. Delete the files .project, .classpath, and folder .settings before you import because those hold data unrelated to your system.
File, Import, Project from existing sources
Pick the inner Personal Diary folder, not the repo folder
You will need to download two libraries to add to the classpath
JSON-Simple and Apache HTTP Client

converting a Webproject into maven project structure

I have the below Web project which is working fine. I wanted to change the structure of the project into a maven project structure.
So, I modified the project to as shown below(I created a new folder called webapp under src/main and I moved the contents of the folder WebContent into webapp and I deleted WebContent folder) Now the application doesn't work although I deploy it in the Tomcat Server. What is wrong in the below project structure . Please help me out
EDIT: I wanted a maven project structure as shown below which is a standard maven project structure
If you are using eclipse (which it looks like you are), you can use the M2Eclipse plugin, which will provide a "convert to maven" utility. Simply right click the project and go to configure -> convert to Maven.
https://www.eclipse.org/m2e/
The structure you are looking for can be defined at the time of project creation in the source directory screen. If you have an existing project you will need to add a new source folder.
To do so,
Add the folders to your project.
Right click on folder > build path > use as source folder.

Eclipse:How to Detect a Project is Part of the Workspace

How can I make sure a project that is shown in my workspace is actually part of the workspace. Below, I will explain what happened so that you know why I'm asking this question.
I had checked out a project into my workspace, and then had configured it as a Maven project by selecting Configure->Convert to Maven Project; in most cases, when I do this, the project becomes part of the workspace. But in this case it hadn't. But I spent a few hours before realizing that I need to import the project in order for the workspace to recognize it as workspace project. So, I want to avoid this situation and be able to look at a flag or file or something that tells me if a project that is shown in the Eclipse window is actually a workspace project.
Thanks
I'm adding the following to make the problem more clear:
This is what I do; I have a workspace with a few projects (all Java/Maven project); everything works. Then I checkout another project from svn into the workspace; so, the folder of the new project is within the same workspace. I expected that as soon as I check out the new project into the workspace, and convert the new project into a Maven project, then the new project be recognized by Eclipse as one of the projects in the workspace. But that is not the case; I actually have to import it.
The project folder is there, and I can see it in the Project explorer. Nothing happens to it, but it is not used by the workspace. For example, if I add breakpoints to the Java files which are in the new project, they are not used. At this point, I use File->Import menu to import the project from the same folder that is already in the workspace, and bang, it starts working, and my breakpoints work.
Is my procedure for checking out a project from SVN into the workspace wrong? I want to fix my procedure to make sure this will never happen. Do you think that even though the new project is a subfolder of workspace, I should still need to import the project into the workspace?
I just noted another fact; this particular project that I'm importing is a Maven multi-module; could it be that the parent project is actually part of the workspace, but the modules inside it are not; therefore, just because it is a Maven multi-module, I need to import the sub-modules.
There are four ways to create a project in Eclipse:
create
Create in a default location (workspace folder on a filesystem)
Create in user-specified location (anywhere)
import
Project is referenced from workspace, untouched otherwise, location on a filesystem is unchanged
Project is copied into default location
You probably want to know if a project is located in workspace folder on filesystem. To do this, you can open project's properties and find location in resource node:
"... in order for the workspace to recognize it as a workspace project..." doesn't make any sense to me. I'm not exactly an eclipse expert, but a workspace is the set of directories in which you are working at one time in eclipse. There can be more than one workspace for eclipse on a given machine.
If you checked it out and it appeared in eclipse, then it was "in the workspace" afaik. Now, Maven tasks create and change files, and those changes do not automatically show up in the workspace -- you have to refresh the project, which essentially syncs the filespace with the workspace.
If that doesn't cover your case, then detail what you mean by "not in the workspace".

Maven package structure changed after build Eclipse

I created a Maven project in Eclipse. Initially my package structure was like
-src/main/java
---com.package1
---com.package2
-src/main/resources
When I build the project successfully and got war deployed in tomcat, My project structure changed to
-src.main.java.com.package1
-src.main.java.com.package2
-src.main.resources
This is generating errors in Java class files in packages import declarations.
I want to restore my original project structure. I have m2eclipse plugin installed in Eclipse.
I also tried Maven>Update Project.. (I read somewhere on Stack Overflow that it will restore the original structure) but it is generating the following error
Failed while installing JAX-RS (REST Web Services) 1.1.
org.osgi.service.prefs.BackingStoreException: Resource /Workspace/ProjectName/.settings' does not exist.
Please help how I can restore my project structure back.
The following helped in my context:
Eclipse Luna (4.4.2) with Maven embedded
Multi module project where folder structure is
parent P
module A
module B
P is a normal Eclipse project while A and B are Maven projects
P is a closed, A and B are opened
the error happened in B with message Resource /P/B/.settings not available
After opening P again the error disappears and Project>Maven>Update Project... works fine.
It seems you have created the src/main/java and src/main/resources as normal folder. Just change them to source folder. It will work.
Steps
1.Go to src folder & Right Click
2.New->Others->Source Fokder
3.Then make the folder structure as /main/java & /main/resources
4.Then add the packages.

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.

Categories

Resources