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

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

Related

How to create a Java EE 7 Maven IntelliJ Project

I am new to Stack Overflow because of my frustration to build a working Java EE 7 Project with Maven and IntelliJ ultimate.
I learned a lot about JPA and JSF in the last weeks and am thrilled to put my knowledge to use but unfortunately I am not able to create a working project structure as I get all sorts of errors along the way. I haven't found a single up to date tutorial which is working on the entire Internet.
My greatest achievement is creating a Maven project, and run the index page on a Jboss Wildfly (11) server.
I know Maven (3) requires a certain structure to work, I read that it is the one in picture 1.
Picture 1
Furthermore I know that I can add framework support by right clicking the project name and that I can add facets or modules by selecting files and project structure.
I would be very thankful if someone could explain the right creation of such a project. I already wasted double digit hours and lost a lot of fun.
I had to create a Maven Project with IntelliJ. After that I added JavaEE Application under Framework Support and checked the boxes for JSF and Web Application under Java EE aswell.
Now this doesn't work alone, I had to put this in the right structure Maven requires. I moved the META-INF Folder to main/src/resources. After renaming the web Folder to webapp, I moved it to src/main.
To check, go to Project Structure/ Facets and check if the paths are set correctly.
After adding a local Wildfly 11 Server Artifact (war), IntelliJ starts the default browser and I get to the index page.
The Project Structure
I recommend you take a look at JetBrains page, they have a lot of tutorials on how to use their products. Here how to create new Maven project:
https://www.jetbrains.com/help/idea/maven.html#maven_create_project
Also, here you have information how an example pom.xml file looks like and how to build it:
https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
When you develop your project you can add dependencies to the pom.xml file

Difference between a JSF and a Maven project

For my new JAVA application, I want to start creating a new JSF2.2 project with IntelliJ. This project will be a web application and will be using maven.
In IntelliJ Idea, when i click on "create a new project", and then in the left panel select "Maven", it gives me the option of "create from archetype". If I select this check box, it gives me a list of archetypes, with many including jsf in their names.
I am confused what is the difference in creating a maven project without these archetypes and giving it my own groupId, artifactid and so on as compared to creating a project with any of the given jsf archetype?
Like I stated above, the project that i am starting will be a JSF based web application.
EDIT 1
I made the project with maven-archtype-webapp and it created a file index.jsp in the webapp folder. Is this a problem as i normally work with .xhtml files
Maven archetypes are templates. They create a proper project structure for you, depending on whether you want to create a standalone, JSF, ear etc. project.
All these projects are built with Maven, and create a GAV (groupId:artifactId:version) for the created artifacts.

How can I create web fragment project in Intellij Idea

I'm looking for creating a small web framework on top of the standard servlet-3.x specifications. Main motive is to reduce the boiler plate codes and abstractions. After I read the servlet specifications it looks without using JAX-RS or SparkJava I can create small web framework for API developments.
I'm planning to use the web-fragments method to create my framework level filters, and other beans and package it as jar. So application developer create the war project with web.xml with the metadata-complete option set to false.
I can see the web-fragment project template in eclipse but I want to develop this project using maven. With Intellij I can't see any such options for web fragment projects alone. I want to create simple maven project which ship the jar with web-fragment.xml in it, so other war projects can make use of it.
So is there any plugins or other options available to develop web fragment projects in Intellij ?
Any jar file added to the WEB-INF/lib directory of a web application is technically a "web fragment", whether it has a META-INF/web-fragment.xml file or not.
Therefore, you just need to create a maven project with "jar" packaging and import it into Intellij Idea.
Create a maven project for the fragment. Set the packaging to jar. There is no need to create a war project.
Configure an empty Artifact in the Project Structure dialog:
Using the toolbar buttons, add the WEB-INF/lib folders. Then create an Archive and add the compile output:
Add a Tomcat run configuration, and in the Deployment tab, add the Artifact you just created:
I created an example project that includes all that: https://github.com/ThomasR/web-fragment-idea. Please note that it requires TomEE+.

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

Reference External Project in Spring Configuration

I am trying to reference a project in my main project. I am a .NET developer so I am having a hard time knowing the correct way to reference it. I have a data project and a data project in a MAVEN multiple project setup. In the screenshot you can see I am trying to reference a DAO object from my data project in the security.xml file in my Spring MVC web project. When I run the project it says it can not find the correct class.
Actually I fixed this by adding a Maven dependency of my project, which created a JAR for Tomcat, and fixed the issue. I didn't know you could search the Maven Local Repository to use your own projects.

Resources