Do JSR-286 portlets require a web.xml file in thei

2019-08-02 20:39发布

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?

2条回答
爷、活的狠高调
2楼-- · 2019-08-02 21:07

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.

查看更多
劳资没心,怎么记你
3楼-- · 2019-08-02 21:24

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.

查看更多
登录 后发表回答