I have created a Java Maven Project in Eclipse and I have put it into GIT.
My project ist a Web-Project and now I have taken a look at the project structure in the "Project Explorer" in Eclipse. It is like this:
So as you can see I have two times the src/main/java and src/test/java folder but why do I do not have the src/main/resources folder in the upper section?
And what is the difference between the two folders, why do I have two times src/main/java and only one time src/main/resources or src/main/webapp?
The folders src/main/java and src/test/java are configured as source folders in eclipse, this is why they are shown at the top.
All other folders, like src/main/webapp, are not configured as source folders. So they are displayed only at the bottom, where eclipse shows the directory structure of your project.
When you have a look in your filesystem, you will notice src/main/java and src/test/java exist only once, despite eclipse showing it twice. This is simply eclipse giving you another view to the folders you need most often.
Related
I am using git with fellow student, now I've noticed that if I load a branch of another student it imports the src folder weirdly.
what could be the problem?
Eclipse is not recognizing your src directory as a source folder, and therefore not displaying the underlying directories as packages.
You need to define the source folders in your project, typically src/main/java and src/test/java (Maven convention).
If someone else's branch uses different source folders than you, then you get this problem when you switch. It might be useful to either follow the same project structure if you work together, or use separate Eclipse projects.
sometimes i face project structures in Package Explorer that are at "src/main/java". But if i work for myself it is only "src". Howto take controll of that?
Difference between two projects in eclipse: left: one folder named "src/main/java" right: one folder named "src", one subfolder named "main.java"
Thanks - Enomine
The default source folder for a Java Maven project is src/main/java. In the project on the right, the source folder is set to src via the following line in the pom.xml file:
<sourceDirectory>src</sourceDirectory>
If you remove the line or change the value, right-click the project and choose Maven > Update Project... to have Eclipse read the pom.xml file and update the source folder location accordingly.
Difference: Let's first understand the meaning of both the folders. In the left image src/main/java is the source folder which is used by eclipse to build the project. In the right image src is the source folder with the package main.java
Solution: It is not possible to edit your source folder So you have to copy your files and create a new source folder with name src/main/java.
#howlger
Project structure and pom
I think i did right now. I clicked right, choosed "Build Path" -> "New Source Folder". Then it worked. With the Properties-Menue "Java Build Path" it didn't work.
Thanks - Enomine
The projects with src/main/java as source folder are maven projects. Maven is a build infrastructure which i.a. manages library dependencies, and provides conventions for the project folders, like src/test/java for unit test sources, and src/main/resources for non-java sources like images and *.properties files.
Best would be to import the project as maven project (here it is not gradle). It might be that you need a plugin in eclipse; for a while I am using an other IDE.
Create a new maven as trial.
Maven projects are controlled by a pom.xml so a recognition as maven project is best.
In my opinion, there are two ways how to solve it:
1. go to project -> build path -> configure build path -> Java build path and then in source tab add your src/main/java folder
2. There is also an arrow near the "Project explorer" which lets you customize your workspace. you can try to change "project presentation" or "package presentation"
I have download a sample project and saw the below package structure.
src/main/java
src/main/resources
JRE System Library
Referenced Libraries
src
main
webapp
css
user
WEB-INF
target
Is it a best way to create the package structure. Normally when we create a dynamic project in eclipse it has one src folder and the WebContent folder in project root. The WEB-INF would be under the WebContent. But here we can identify two source folders and instead of WebContent we find webapp under the source folder not in root.
Despite its correct package structure or not i try to create the same in eclipse. But i cant rename the src folder to something like src/main/java know. It gives me an error
Cannot nest source folder "src/main/java" inside source folder "src".
in eclipse when create a dynamic project
This structure is maven based web base project and mostly for maven base project this structure is used, and as for as new conventions Maven is most popular deployment tool, so I myself recommend the maven base architecture.
If maven drives this organization a maven plugin exists, its goal is to generates eclipse projet.
A second plugin (an eclipse plugin) exists to faciltate the integration into eclipse.
The src/main/java folder is an automated updated duplicate of src folder. (These are the build paths configured in your project)
You should edit your files in src and the changes will be updated by eclipse to their symlinks.
First of all, its only one src folder. Eclipse displays them in such a way to make it easier to access different parts of the project. Webapp is main WebApplication Folder which contains all the goodies. The other most important folder is WEB-INF this is folder which is read protected from the client side so, you have your Java Class files and any thing which you want to protect from the client inside this folder. This folder also, contains a lib directory to contain the JAR files. This is the main overlay for the directory structure.
If I want to have a project with both EJB/JPA sourcecode and JSF in the same project how do I set up a project like that in Eclipse? I am using Maven. Is it correct on the image below? What is the difference between source folder and folder in Eclipse, and why do I have structure twice in the project below?
GO TO http://i.stack.imgur.com/RCmI8.png for full size picture.
Yes, the structure you have is a typical folder layout for a Maven webapp project. Eclipse highlights the folders containing source code that will be compiled / placed on the classpath, but also shows you the regular folders in the filesystem.
When i create a new Maven project in Eclipse, directory structure contains both src/main/java and src/main (down below)
Question:
I understand my code should fall under src/main/java, what is the purpose of the src/main? Why does Eclipse create it?
src/main/java is Maven's standard layout for placement of your Java source codes.
Check http://java.sg/maven-standard-directory-layout/ for a list of standard Maven directories.
src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
LICENSE.txt Project's license
NOTICE.txt Notices and attributions required by libraries that the project depends on
README.txt Project's readme
For src/main/java to exist src/main/ must first exist so eclipse just shows you all the folders in your project including src/main/
If you want to remove them from your view in package explorer, you can create a filter for the package explorer view and exclude Non-Java elements.
Look for the down arrow in the top right of the package explorer view for the filters option.
You can have other sub-directories under src/main that are not source files.
If you see Maven documentation you need to have resource files under src/main/resources.
Obviously the parent directory src/main needs to be created to create child directories.