Where should I add what in a Smart template project in STS? - spring

There are a lot of folders in a Smart Template project in STS. My question is where to add what?
There are 4 folders under SRC
1. Main/java.
2. Main/resources.
3. Test/java.
4. Test/resources.
Should I add my controllers in all the above folders or in a few or or or..?
There is another folder called SRC!
Should I use the 'view' folder for adding all my web pages (say JSP pages)?
Can anyone please elaborate?
Also please let me know if using Dynamic Web Project is a better option than using Spring Template project or vice versa?

This folder structure is the structure of an maven project.
Java classes for your application should be in src/main/java for example src/main/java/com/example/web (com.example.web is the package)
The JSPs should be in src/main/webapp/WEB-INF/jsps (you can use an other subfolder then jsps but it must be below src/main/webapp/WEB-INF/)
Also please let me know if using Dynamic Web Project is a better option than using Spring Template project or vice versa?
If you know Maven then the Spring Template is better (in my opinion).
BTW It is important to have pom.xml in the project root.

Related

Web/maven project struture in eclipse Luna

To start a new web project in Luna, I follow below steps.
1) Create a new Dynamic Web Project
2) Convert it into Maven by clicking configure option
The below is the obtained structure
http://i.stack.imgur.com/7Ph9M.jpg
This web project structure looks completely different from the one I see in the tutorial I follow. There the project structure is as follow
http://www.mkyong.com/wp-content/uploads/2010/06/Struts2-login-form-folder-stucture.jpg
I am not sure if the project structure is changed in new version or if I am doing something wrong. I made almost everything work but doesn't know where to place resources folder ( where we keep all our properties file ).
Can somebody assist me on how to create a new Struts2 project with proper structure :)
I found the answer here in this tutorial :D
http://o7planning.org/web/fe/default/en/document/300723/struts2-tutorial-for-beginners-annotation-configuration
I should have created Maven Project and picked web-app archetype. It is very simple.

Explain structure of Eclipse-Maven Web project in Spring using Kepler

I am using Kepler to build a Eclipse-Maven project in eclispe. While making the project I am skipping archetype selection on first wizard. then I am selecting packaging as "war".
Eclipse provides me a basic structure after above steps. However, as this is my first Spring/Maven application, I am unable to completely understand the structure.
My Main issue is where to keep my web.xml. No WEB-INF folder is provided, while a META-INF folder is provided.
Also where to keep the basic Dispatcher-Servlet for project and others like root-context, servlet-context etc..
Do I need to create these folders by myself. If yes, Where please? As I am creating a RESTful service, I won't have any views but I guess web.xml is still a must. Currently I am unable to upload an image(nothing happens when I try uploading), will try again soon.
While making the project I am skipping archetype selection on first
wizard. then I am selecting packaging as "war".
You need to select the maven archetype as: maven-archetype-webapp to get the WEB-INF folder & web.xml
Check this out

Why servlets can be created only under the resources folder?

I'm trying to develop a new java web application from scratch. I'm using the IntelliJ IDE, and maven build tool.
Why servlets can be created only under the resources folder ?
Why jsp filels can be created only under the webapp folder?
Thanks
Sounds like you need to do some research into how Maven is building your project.
You should create servlets under src/main/java folder.
Run the maven build and then explore the generated WAR file, this way you can get an idea of how Maven is structuring the project.
You should see the that the webapp folder is in fact simply deployed at the root of the WAR file, hence your JSPs are placed in the correct location.
Thanks everybody, but i resolved the issue myself.
The Solution:
Go to the folder which you want to make available for java classes or servlets, and right click it.
Choose: Mark directory as...
Choose: Sources Root

recommend folder structure for liferay maven project using liferay developer studio

We just started with a liferay extranet project. We want it to be as much mavenized as possible. So far I read how to get it working with Maven and have a working setup. But I have some questions regarding the folder structure:
Do I need an (unpacked) sdk at all?
How should the folder structure look like (in future there will be many portlets, themes, exts... plugins)?
at the moment my structure looks like this:
liferay-portal-6.1.20-ee-ga2 (liferay tomcat bundle)
|-deploy
|-tomcat-7.0.27
|...
project-folder
|-pom.xml (parent pom)
|-sample-portlet (created with archetype:generate)
Is this ok? or it is probably better to create subfolders for each plugin type? does this interfere with the archetype and the automated connection between parent-pom and modules?
Does the mavenization changes something with workflow of liferay developer studio? This will be the ide of choice.
To answer your questions
You don't need plugins-sdk at all!
I advice you to go for a multi module maven project, and I already see you using it.
Obviously when you go for a multi-module project you have the sub-folders created and each module corresponds to a separate archetype and of course, it depends on what type of project you create.
Here is the sample liferay-maven project structure I had.

Correct directory structure for Spring 3 / JSF 2 application?

At work, I have seen several ways of setting up a directory structure for this type of app. Maybe there is more than one correct answer. Here is how I am setting up my directory structure - is it correct? Or is there a better way of configuring it? (I am packaging this in a WAR file)
/webappTopDir
/src
/main
/java (controllers and other classes)
/webapp
/subfolder1 (Spring secured subfolder)
/subfolder2 (Spring secured subfolder)
/resources
/js
/images
/css
/WEB-INF (contains application-context.xml, security.xml, faces-config, web.xml, and spring taglibs)
/classes (contains custom JSF messages and logging properties)
META-INF (contains persistence.xml)
/lib
/templates
/META-INF (contains context.xml)
This structure works, but I still want to make sure it is best practice. What I find really odd is the META-INF under WEB-INF/classes, but from what I see in the Oracle docs, that is what you need if packaging your app into a WAR Oracle Managing Entites.
In my case, META-INF directory is under WebContent directory. I think what you've thought odd was right. But definitely there's no right or wrong way. There is just a better way.
The term "correct" implies that there is an objective standard for folder layouts. Here are the objective standards that I know about:
Project specific layout. Whatever history the project is embodied in the layout and you should continue to maintain that layout until your are forced out of it.
Developer community layout. Your shop determines how the layout is implemented. This layout was built up through a number of generations of programmers and the developmental forces that are being addressed. Changing a developer community mind set is not an easy job, even if it is just yourself.
Build tool layout. Many build tools have specific layouts because of the conventions used by the toolset. Make, Ant, Seam 2, Spring, Maven 1, Maven 3, JBoss Forge all seem to have their own conventions arising out of the developer communities that created the toolset. Each toolset has ways of customizing the layout.
Library/framework layout. Spring has a (set of) specific layout(s) that work well with its build set ups.
To answer your specific question though, I suggest that you use a Spring template to build out your directory layout. You might try the following tutorial:
http://static.springsource.org/docs/Spring-MVC-step-by-step/
As you follow the tutorial, learn the reason why the Spring build chain needs things to be in specific locations. This allows you to justify the tutorial layout, and apply similar reasoning to your own application layout.

Resources