dynamic web project package structure - java

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.

Related

Maven Spring project structure in Eclipse

I have a Maven project in Eclipse which I am using to build a Spring MVC application. However, I am very confused about how the project structure should be. I've looked at various sources online and they often differ.
My current project structure (a bit of a mess..):
Which source folders do I need in Java Resources? Obviously src/main/java and src/test/java but what about src/main/webapp? What goes in there?
I see that there is a src directory generated when I build the project. What's the purpose of this directory?
Do I put my static resources e.g. 'style.css' in WebContent/resources or in a different directory?
Finally, how should my Deployment Assembly mappings look?
Update as per suggestion (not yet solved):
src/main/webapp contains the css html and js related files. if you are aware of webContent folder the same things resides inside the webapp folder.You will need to remove the webcontent folder and place all the files in src/main/webapp folder.

Intellij Can't find file in path

we have a java project created with maven with standart folder tree, that generate maven. we put our xml files and log4j propertie files in resources folder which locates in one level with src folder. in resources folder we have ApplicationSetting.xml and in Eclipse when we write in class "resources/Applications.xml", everythong works nice, but not in Intellij. there we get FileNotFoundException. works only if I'll write "Application/resources/ApplicationSetting.xml". is there any way to write file path as in eclipse. in our team somebody uses eclipse, others intellij.
EDIT:
Folder structure is:
Application
resources
src
main
java
test
the project name in BackEnd and in it we have 4 modules: Application, Configuration, DataLogic and BusinessLogic. In "Edit Configuration" of Intellij working directory is BackEnd, classpath module is Application
Ideal maven structure should be :
src
-main
-java
-resources
-test
-java
-resources
One disadvantage of your folder structure is manual path setting for your resources
and
there is no separation between your source resources and test resources.

How to structure a maven project in Eclipse

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.

Eclipse & JAR Hell

EDIT: I appreciate the suggestions for Ivy or Maven, but this is just not an option for me at this time. I do not have the authority to use those tools. I am simply looking for a way to get my referenced .classpath JARs into a folder inside my project.
I have created a project that uses about 50 external JAR files that I referenced from other projects inside the same workspace.
Thus, my project's directory strucure looks like:
MyProject
src/
test/
Referenced Libraries/
... 50+ JARs
lib/
My project compiles and runs beautifully inside Eclipse. But now I need to add a buildscript so other developers can pull the project down from SVN and run it standalone. To do that, I'd like to place all the JARs that are currently in Eclipse's in-house directory Referenced Libraries and copy them into my project's lib directory which I will JAR-up with the final distribution.
I'm in Package Explorer, and have tried to just copy + paste the files from Referenced Libraries to lib/ and no dice. I get the following Eclipse error:
Cannot paste the clipboard contents into the selected elements.
Anybody have any idea how I can force this copy operation to work? If I right-click any JAR inside Referenced Libraries I see an Eclipse option called Migrate JAR file, but I'm afraid that would cut-n-paste the JARs from their current location to the new lib/ directory. This isn't feasible because there are many other projects that need these JAR files exactly where they are.
Thanks for any insight here!
Have you considered Maven? It's an exceptional tool for situations like this. For file operations it's best to use Navigator view.
I don't find another way to go but to copy yourself the jars into your lib folder, add the references to your lib files (not to external jars on your machine) and upload it to SVN.
EDIT to clarify:
Remove all references from your build path. Now you can't compile the project.
Copy every jar file you need to your project's lib folder.
Go again to build path and add the references to your jars (the ones on lib) one by one. Use the button that says "Add JARs...", not the one that says "external JARs".
Compile, and if everything is fine,
Upload the whole project to SVN.

Java Project vs Maven Project (Eclipse), dir structure clarification needed

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.

Categories