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.
Related
I have createdd an EJB project for writing Entites,DAO and Facade classes. But There is no any persistence.xml file in my project. Otherwise I must create a persistence.xml.
Eclipse will only include a persistence.xml file if you add the JPA facet to the project. Right-click the EJB project, go to "Project Facets" and check the box next to "JPA".
Make sure you enable the Dynamic Web Module 3.0 facet in your project.
Either that, or add it manually. It's doesn't make a difference.
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.
I have read this on how to auto-generate the Entity Meta Model, but I think there is something wrong.
I have: Eclipse Indigo SR2, build 20120216-1857 and configured the "Annotation Processor" as specified here. To the factory path I have added ONLY these jars
hibernate-jpamodelgen-1.2.0.Final.jar (taken from here)
hibernate-jpa-2.0-api-1.0.1.Final.jar (taken from the zip archive of Hibernate ORM 4.1.0 from here)
I suppose after configuring this for my the EJB project (I did not do that for my Web or EAR Project), the project gets rebuild and the Meta Model Classes will be autogenerated, without clicking on another button, is that right?
If everything should have worked, do you have any clues on what could go wrong?
Notes:
I see absolutely no messages from any annotation processors in the "Error Log" Eclipse View.
My persistence.xml file is in the ejbModule/META-INF/persistence.xml
All my entities extend an Abstract class, imported in the project with svn:externals.
My entities are annotated with #Entity, and that's all.
The problem is that the project has also AspectJ compatibility, which makes the Project use another compiler. More details on this bug here.
Beside that, you could (bun not mandatory you will) get an NullPointerException (see the "Error Log" Eclipse View) if you have at least an Abstract Class in your project.
You just need to select the source folder of the generated metamodel on your Project -> Properties -> JPA
I'm using IBM RAD 7 (aka Eclipse 3.4) and WebSphere 7.
I have a workspace with a basic EJB setup; projects TestEAR, TestEJB, TestJPA, TestWeb.
I can annotate an ejb ("#Stateless EntityService") in the TestEJB project and it works fine. But if I put an ejb ("#Stateless EntityDAO") in the TestJPA project it doesn't get injected in the EntityService. If I move EntityDAO to the TestEJB project it works fine.
Also, if I annotate a class an entity ("#Entity MyEntity") it is not known as an entity to the container (I get a "not recognized entity" ... "Known entity types: []" error). But if I add a my.domain.MyEntity tag to the TestEJB's persistence.xml it works fine.
QUESTION: Why can't the TestEJB project recognize annotated classes in the TestJPA project?
NOTE: There is no "Deployment Assembly" tab in Eclipse 3.4, but there is a "Java EE Module Dependencies" tab (TestEAR > Properties > Java EE Module Dependencies); I checked and all projects are in the list and checked (ie. TestEJB, TestJPA, TestWeb).
Any help is greatly appreciated! This one has me truly stumped.
Thanks,
Rob
Seems there are a few questions here...
For your TestEJB project not using TestJPA beans make sure both are listed as an <ejb> module and not <jar> module in your application.xml file in TestEAR. Also make sure they are both part of the EAR.
For the No Known Entity types if that error is appearing within RSA you might want to right click on the project and look for "JPA Tools" and select "Configure JPA entities", if you do not see "JPA Tools" ensure JPA facets are enabled for that project. If it is occuring on the server (WAS I presume) make sure the following line is not in your persistence.xml <exclude-unlisted-classes>true</exclude-unlisted-classes> or all classes will need to be listed therein, not necessarily a bad thing.
Unless it is absolutely critical I would store your EJBs and Entities in the same project for simplicity.
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.