Do JSR-286 portlets require a web.xml file in their WAR files?
Asked Answered
C

2

1

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?

Chrystel answered 5/1, 2012 at 21:6 Comment(1)
It just needs a portlet.xml as far as I know.Allanite
B
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.

Bowen answered 9/1, 2012 at 13:42 Comment(1)
One can see the code here. So, a portlet WAR without a web.xml just get one from the deployer. Well, this does not answer my specific question, but clarifies it anyway! I'd like to know about the spec but your answer is enough for now.Chrystel
M
1

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.

Meditate answered 5/1, 2012 at 22:56 Comment(0)
B
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.

Bowen answered 9/1, 2012 at 13:42 Comment(1)
One can see the code here. So, a portlet WAR without a web.xml just get one from the deployer. Well, this does not answer my specific question, but clarifies it anyway! I'd like to know about the spec but your answer is enough for now.Chrystel

© 2022 - 2024 — McMap. All rights reserved.