问题
Does the JSR 286 spec require the presence of a web.xml
file in WARs containing portlets? At first, I thought so but then I created a portlet without a web.xml
, deployed it in Liferay and it worked flawlessly. So is it an extension (or a bug) of Liferay, or is it not necessary to have such a file?
回答1:
As Olaf rightly said portlet is nothing but a web application. Liferay has a listener that gets triggered when the portlet auto deploys. It explodes the war and adds web.xml and the content that is necessary. You can check the logic if you have source. The class name is PortletDeployer and the method is getServletContent. After add the web.xml and stuffing it, they just touch it using FileUtil.touch.
回答2:
I'd really have to dig in the spec - but my assumption is that it's following the servlet spec in this regard: A portlet app is first and foremost deployed to an application server. If the servlet spec requires a web.xml to be there, this requirement would need to be fulfilled. Otherwise the Appserver would not deploy the WAR (it's more or less the question if the WAR file format requires or recommends web.xml
Liferay will only kick in once the Apperver has deployed a web application. Liferay itself doesn't care for web.xml
Based on this arguing (and without looking at the spec - so I'm giving an educated guess here) I expect JSR 286 to not make a statement about web.xml. However, it probably references the servlet spec and this in turn might require/recommend/mention web.xml.
And if the Appservers require it or how they behave if it's missing is yet another story.
来源:https://stackoverflow.com/questions/8749818/do-jsr-286-portlets-require-a-web-xml-file-in-their-war-files