Deployment Descriptor is not updating? - eclipse

I have installed a brand new Eclipse Java EE version. But my web.xml is not updating automatically as it should while creating a Servlet. Initially it just has the welcome tags, that is all.

This could be because you are using the Servlet 3.0 specification. web.xml mapping is not required for it. Check whether you have the WebServlet annotation in your servlets. It should do the required thing.
Servlet 3.0 uses annotations for URL mapping and not the web.xml servlet configuration tags.
E.g. If you are creating a Servlet called HelloServlet then in your HelloServlet, you will see the WebServlet annotation in it.

Related

What is Eclipse referring to with the warning "No JAX-RS Activator is defined for the project"

Eclipse is warning "No JAX-RS Activator is defined for the project".
What does it mean?
Note: This is not a duplicate of the question How to get rid of "No jax-rs activator is defined for the project" warning?
- I don't necessarily want to remove it from displaying. I want to understand it.
I'm guessing you have the JBoss tools installed.
The JaxRsActivator class initializes JAX-RS without the need to use a web.xml file. This is achieved by extending the Application class and using the #ApplicationPath annotation. The value provided in the #ApplicationPath annotation defines the root path for all other JAX-RS HTTP calls.
The second answer to the linked question, which turns off the feature rather than the validation, would seem to apply.

Validating Null and Empty Strings using Jersey

Can I have a web deployment descriptor file, web.xml, with a Jersey project that runs on top of a Grizzly container? I want to constrain my resource to ensure that input is provided, using #NotNull.
Some context...
I'm using Jersey 2.19 to implement a REST API.
Following the 'Getting Started' section of the user guide I successfully created a new Jersey project that runs on top of a Grizzly container using a Jersey-provided maven archetype.
I have also successfully implemented some bean validation by annotating a resource with various built-in constraints.
I would like add a #NotNull constraint to my resource and for it to mean that input is required - i.e. for an empty string to fail this validation constraint.
The Java EE tutorial refers to making a change to web.xml but there isn't one in my project. I see from the user guide that if I'd created a JavaEE web application instead then the web.xml file would be present.
Can I add one? Or is there another way to validate empty strings in the way I want?
UPDATE
Chapter 18 of the Jersey User Guide does not tell me what I need to know. The Java EE tutorial indicates that I need to set javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL in the web.xml file. What is the equivalent of that if I don't have a web.xml?
javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL is a JSF parameters so it will have no affect on Jersey. Since The default implementation for bean validation with Jersey is Hibernate Validator, you can use it's annotation #NotEmpty. It should serve similar purpose as the JSF parameter (to fail on empty strings).

Where is the location of web.xml file in CQ5.5?

I wanted to know how the Servlets are mapped in CQ5.5. As in the previous version(CQ5.4) there used to be a Server folder but this seems to be changed now in this version. I searched for it in the complete cq-quickstart repository but could not find. Where can I see the web.xml file?
Thanks in Advance !
In CQ, like in Apache Sling, you dont need a web.xml to map servlets. They are registered as components with some properties. You can use some simple annotations to register a servlet under certain resource type or path. Adobe has some instructions.
You Basically annotate your servlet class with the #SlingServlet annotation. You can register a servlet into a specific url or you can bind it into a particular resource type

Eclipse does not put servlet mappings into web.xml

I have added new servlet to eclipse project with it's wizard and wizard also asked for servlet mapping. Now I can see this mapping in project explorer tree under Deployment descriptor - Servlet mappings, but web.xml does not contain this mapping.
Is this an eclipse bug or mappings are stored somewhere else nowadays?
Mappings do work.
Eclipse is Indigo.
Tomcat is 7.0
Mappings are set with #WebServlet annotation now.

No web.xml in Eclipse + Glassfish v3?

I created a simple "hello world" servlet in Eclipse (helios) + Glassfish v3. I am using Glassfish's plugin for eclipse It seems there is no web.xml but a sun-web.xml in the WEB-INF/ folder. This is my first time with glassfish but was a bit surprised at the absence of web.xml - so here are some of the problems:
Where do I check for url-mappings for the servlet? On creating a new Servlet in Eclipse it asks me for a URL-mapping but I'm unable to find it anywhere in any .xml file where I can tweak the settings.
If there isn't any web.xml, creating it from scratch will be quite error prone. What do you suggest? Google for a sample and play around? Shouldn't one be auto-created?
Has anyone encountered this? I tried looking up the difference between web.xml and sun-web.xml but the results weren't at all enlightening. I wouldn't want to learn another xml for configuration purposes and that too glassfish specific.
We have to configure servlet contexts, mappings etc especially during development/testing but the sheer absence of web.xml has me stumped.
Eclipse allows you to not create a web.xml file when you create Dynamic Web Project for Java EE 6, since the Java EE 6 spec (in general) and Servlet 3.0 spec (in particular) attempt to de-emphasize deployment descriptors.
You can use annotation to provide all the data that had been included in the web.xml file. The Javadoc for the Servlet 3.0 annotations is pretty obtuse. You should read through the Servlet 3.0 spec from the jcp.org site to get a bit more explanatory text.
To change the url-mapping for a Servlet 3.0 servlet, the first place to look is in the source code for the servlet. Look for (and change) the value of the urlPatterns element.
If you are trying to create a web app based on Servlet 3.0, try to avoid creating a web.xml file.
The sun-web.xml/glassfish-web.xml file is used to 'finish' the description of a war file for deployment into a GlassFish container.
One other note about the annotations like WebServlet... they do not integrate your annotated class into the class hierarchy, so the correct use of #WebServlet would look like
#WebServlet(
name = "MyServlet",
urlPatterns = {"/path_to_servlet"}
)
public class MyServlet extends HttpServlet {}
If you find you do need a web.xml file, you can context-click on the deployment descriptor in the Project Explorer view and there should be an option "Generate Deployment Descriptor Stub". That will create a web.xml for you with the display-name and welcome-file-list elements.
It seems that it's a bad habit to click "Finish" when you create a 'New > Dynamic Web Project' - You should keep clicking 'next' and go the last window-pane where you select "generate web.xml deployment descriptor" - seems it's unchecked by default.
Well that says I've been a bit rusted with creating web-apps. And here I thought it was a glassfish specific issue.
Because of Glassfish 3.x is fully certified Java EE 6 server, it supports Servlets 3.0. Starting from Servlets 3.0, it is possible to specify web.xml settings through annotations.
For example
#WebServlet(
name = "MyServlet",
urlPatterns = {"/path_to_servlet"}
)
public class MyServlet {}
To add to what TMN said, I noticed that the project explorer would not show the Deployment Descriptor until I performed an SVN update for some reason. If you have that problem, try updating your code. I was on the HEAD revision already but for some reason the update showed that view.