Why servlets can be created only under the resources folder? - maven

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

Related

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

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+.

Eclipse Juno m2ecliipse : directory structure explanation

I'm working under Eclipse Juno on a maven-archetype-webapp project done with m2eclipse.
I don't understand directory structure. Anyone could explain how it's working?
Thanks
What i src/main/ressources for ? When you create package, it's not showed as package but only directory.
I create a /src/main/java package and it's where i put my classes. The package structure hierarchy is ok.
What is librairies ressources? Is it where you put javascript jquery? but when i put jquery plugin it does a lot of effor in the project manager. And i want my javascript under /webapp/javascript... What is ECMAScript Library ? What to do with that, what is for?
Same question about Deployed Ressources and target and Jax-WS Web Services ?
Ok target must be the directory when you build the project maven, but i can't see the war file. When you run build how to configure it in eclipse to generate the build? What is the command ?
Thanks , i know it's a lot of questions but i'm beginner !
Have a great day :)
I just add the example when you put jquery in webapp
All of this is explained here.
src/main/java This is where your source code goes
src/main/resources This is where you put your resources like your xml files. Things that aren't java classes but need to be in your classpath. If you put them under /java, they won't be copied into your classpath so you have to put them here.
src/main/webapp This is for webapps. Everything you put in here will be copied over to your war file, directly.

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

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.

Adding existing source packages to a Maven Web Application in Netbeans

I have a normal Netbeans project, and I would like to add the source packages of this project to a project that is a Maven Web Application, also within Netbeans.
I tried copy-pasting the packages into the /src project directory of the Maven application, but this doesn't seem to work.
Could someone please tell me how I could do this ?
If this is not possible, could someone tell me if I can convert the entire normal project into a Maven Web Application ? Thank you :)
It sounds like you need to add the dependency to your web-application instead of the source code, cause maven is intended to handle exactly such situations.

Resources