To be more literally answering your question, and copying pasting code from
that wiki page in large part, it might look like this:
---start src/main/java/helloworld/HelloWorld.java which after war deployed
becomes
/path/to/tomcat/webapps/webapp_name/WEB-INF/classes/helloworld/HelloWorld.java
---
package helloworld;
import javax.portlet.*;
import java.io.*;
public class HelloWorld extends GenericPortlet {
public void doView(RenderRequest request,RenderResponse response)
throws PortletException,IOException {
// Get our preferences
PortletPreferences pref = request.getPreferences();
// Get the value of "displaytext" from our preferences, if not available,
// then use the second string passed to the function
String displayText = pref.getValue("displaytext", "MISSING:
display-text");
// displays the string from our preferences
response.setContentType(request.getResponseContentType());
PrintWriter writer = response.getWriter();
writer.write(displayText);
}
}
---end HelloWorld.java---
---start src/main/webapp/WEB-INF/web.xml which after war deployed becomes
/path/to/tomcat/webapps/webapp_name/WEB-INF/web.xml ---
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>HelloWorld</display-name>
<description>Hello World Portlet</description>
</web-app>
---end web.xml---
---start src/main/webapp/WEB-INF/portlet.xml after war deployed becomes
/path/to/tomcat/webapps/webapp_name/WEB-INF/portlet.xml ---
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0">
<portlet>
<portlet-name>HelloWorld</portlet-name>
<portlet-class>helloworld.HelloWorld</portlet-class>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>HelloWorld</title>
<keywords>Hello, world, test</keywords>
</portlet-info>
<portlet-preferences>
<preference>
<name>displaytext</name>
<value>Hello, from your preferences</value>
</preference>
</portlet-preferences>
</portlet>
</portlet-app>
---end portlet.xml---
with Pluto related jars put into /path/to/tomcat/shared/lib (and if tomcat6
then /path/to/tomcat/conf/server.xml modified to support use of shared/lib).
On Jun 3, 2010, at 2:01 PM, Gary Weaver wrote:
> If you look at that second link I sent:
> https://wiki.jasig.org/display/PLT/Hello+World+Portlet
>
> It has an example simple web.xml, portlet.xml, etc. If you are new to Java or
> Java web applications, you probably out to read up on that and Maven prior to
> getting into the portlet side of things, though.
>
> As for where to go after Hello World, I lot of people use Spring Portlet MVC,
> in which case you might do something like this in web.xml (I tried to strip
> out the unnecessary parts, but not sure how good of a job I did):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
> 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
> <web-app>
> <display-name>yourportletname</display-name>
> <description>Description of the portlet</description>
> <context-param>
> <param-name>contextConfigLocation</param-name>
> <param-value>
> /WEB-INF/context/portlet/nameofyourportlet.xml
> </param-value>
> </context-param>
> <context-param>
> <param-name>webAppRootKey</param-name>
> <param-value>some.parent.package.newofyourportlet</param-value>
> </context-param>
> <listener>
>
> <listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
> </listener>
> <listener>
>
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
> </listener>
> <servlet>
> <servlet-name>ViewRendererServlet</servlet-name>
>
> <servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
> <load-on-startup>1</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>ViewRendererServlet</servlet-name>
> <url-pattern>/WEB-INF/servlet/view</url-pattern>
> </servlet-mapping>
> </web-app>
>
> And could look at this as an example of spring context, pom.xml, portlet.xml,
> etc.: https://source.jasig.org/sandbox/MailPortlet/tags/rel-2.0.0-alpha-7/
>
> There are also a Grails Portlet project and a Rails-portlet project, I think
> both aimed at JSR-286 implementations like Liferay (I know the latter is at
> the moment).
>
> If you want to see what is it really doing in the assembly portion, look at
> FileAssembler.java. For example I found it here:
> http://github.com/apache/pluto/blob/trunk/pluto-util/src/main/java/org/apache/pluto/util/assemble/file/FileAssembler.java
>
> Gary
>
>
> On Jun 3, 2010, at 1:33 PM, Søren Blidorf wrote:
>
>> Thanks Gary. I will look at it.
>>
>> When I use mvn package I get a build error - invalid web.xml.
>>
>> Does anybody know what is needed in the web.xml for maven to concider it
>> valid?
>>
>> Soren
>>
>> -----Oprindelig meddelelse-----
>> Fra: Gary Weaver [mailto:[email protected]]
>> Sendt: 3. juni 2010 17:22
>> Til: [email protected]
>> Emne: Re: Help setting up hello world
>>
>> Soren,
>>
>> Assuming you are talking about this hello world example?:
>> http://portals.apache.org/pluto/v20/deploying.html
>>
>> I also just found another example, even though it is geared for uPortal
>> rather than the example Pluto server. (But uPortal uses Pluto and supports
>> JSR-168 compliant portlets, so should work.):
>> https://wiki.jasig.org/display/PLT/Hello+World+Portlet
>>
>> Some other example portlets are here:
>> https://source.jasig.org/portlets/
>> there are also some in here but not all of these work:
>> https://source.jasig.org/sandbox/
>>
>> As of 2010/06/03 I'm not sure how any of those if any are JSR-286 (most are
>> still JSR-168), but that shouldn't matter afaik just to get something simple
>> working.
>>
>> Some miscellaneous tips/notes:
>> * Pluto's jars should be in the shared/lib area, which requires some change
>> to the default Tomcat 6 config to have it look for. That is the most
>> appropriate place for it, afaik.
>> * Like any war, if you unzip the war, it should unzip its contents into the
>> current directory (i.e. is isn't unzipping into (webapp directory name)/...
>> ). That is just a war thing, not specific to portlets. This only matters if
>> you tried to make the war by hand.
>> * Pluto's assembly API must be used to prep the war. There is a
>> maven-pluto-plugin that can help with this (it uses Pluto assembly). Pluto
>> assembly looks at the portlet.xml then modifies the web.xml and adds
>> portlet*.tld file(s).
>> * Even though Tomcat is much more lenient when it decompresses a war, Pluto
>> assembly (used by maven-pluto-plugin) uses the standard Java API to unjar
>> the war, and if the META-INF/MANIFEST.MF file isn't the first entry (and
>> there should be only one manifest), it will choke (and the error is not that
>> helpful).
>> * Just because maven-pluto-plugin preps the war doesn't mean it is a valid
>> portlet (or even valid web.xml and portlet.xml for a portlet) or that it
>> will even register in Pluto afaik. You need to make sure that web.xml is
>> cleaned up and that you didn't try to add the stuff that Pluto assembly puts
>> into it. (For info on how to clean it up if you need that, see the unplutofy
>> project).
>> * In newer versions of pluto (not sure what version, but sometime between
>> 1.0.0-RC2 and 1.1.7), portlets register themselves with pluto (I think). So
>> you can someone tell if a portlet is available and at least valid enough for
>> Pluto to register it (although it still may not work) if the logs showed
>> that it registered. It may not register each time though? Registering is
>> different than just Tomcat deploying the war (it is the line right after
>> that in the logs usually, I think).
>>
>> Hopefully none of that info is wrong, and please anyone feel free to correct
>> or clarify those.
>>
>> Wish I could provide more info, but maybe some of that will help.
>>
>> Gary
>>
>>
>> On Jun 3, 2010, at 5:58 AM, Søren Blidorf wrote:
>>
>>
>> Hi.
>>
>> I am new to portlets and Pluto.
>>
>> I have installed Pluto on my existing Tomcat and it works fine.
>>
>> However I am having difficulties setting up a helloworld portlet.
>>
>> I have created the portlet.xml and the helloworld.java. Compiled and deploy
>> but nothing happens.
>>
>> I have tried different examples on google, but nothing works.
>>
>> Does anybody have a helloworld.war file of a describsion for dummies on how
>> to get a helloworld to work.
>>
>> Soren
>>
>>
>