5 Replies Latest reply on Oct 9, 2008 11:06 AM by peterj

    Portlet Instance Class Path

    bsisson

      I've looked at a couple of portlets that I've been ablet o unzip and get running on the JBoss Portal server. I'm still having problems actually developing my own portlet and getting it deployed. I'm using the Eclipse IDE. In an exampe I've create a project and set the output folder as: HelloWorldPortletTest/WebContent/WEB-INF/classes This is where my classes for my java files will be placed after the build. I believe that the portlet-instances xml file is setup to point to this class so to generate an instance. Does it make a difference if I build the class files when I drop it into the deploy folder on the server or do I have to convert the class file to a jar?

      I had noticed that a similar portlet that I had unzipped had a lib directory with the jar file and not a class file.

        • 1. Re: Portlet Instance Class Path
          peterj

          Placing your portlet classes in a jar or leaving them in the web-inf/classes directory does not matter. Just as long as your portlet is packed in a WAR it should be ok.

          Have you see the portlet tutorial for JBoss Portal at http://docs.jboss.com/jbportal/v2.7.0.B1/referenceGuide/html/tutorials.html?

          • 2. Re: Portlet Instance Class Path
            bsisson

            I tried to create the tutorial that you referrenced in Eclipse and deploy it.

            I ended up with the 4 xml files specified (default-object.xml, portlet.xml, portlet-instances.xml, and web.xml) under WEB-INF.

            I have a path WEB-INF/classes/org/jboss/portal/portlet/samples to my SimplestHelloWorldPortlet.class

            In addition, I have a WEB-INF/lib directory that contains the following jars: explode.jar, portal-common-lib.jar, and portlet-api-lib.jar I needed to add these jars for the class file.

            I zipped everything beneath the WebContent directory which included the WEB-INF and META-INF contents. When I dropped it into the deploy directory I get the following error message:

            16:04:42,134 WARN [PortletAppDeployment] Failed to create instance SimplestHelloWorldInstance of portlet /SimplestHelloWorldPortlet.SimplestHelloWorldPortlet because portlet /SimplestHelloWorldPortlet.SimplestHelloWorldPortlet is not available

            The tutorial did not specify the contents for web.xml so I used the following:

            <?xml version="1.0"?>
            <!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>
            </web-app>


            Here are the contents for the remaining xml files:

            portlet-instances.xml:

            <?xml version="1.0" standalone="yes"?>
            <!DOCTYPE deployments PUBLIC
             "-//JBoss Portal//DTD Portlet Instances 2.6//EN"
             "http://www.jboss.org/portlet/dtd/portlet-instances_2_6.dtd">
            <deployments>
             <deployment>
             <instance>
             <instance-id>SimplestHelloWorldInstance</instance-id>
             <portlet-ref>SimplestHelloWorldPortlet</portlet-ref>
             </instance>
             </deployment>
            </deployments>


            portlet.xml

            <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
             http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
             version="2.0">
             <portlet>
             <portlet-name>SimplestHelloWorldPortlet</portlet-name>
             <portlet-class>
             org.jboss.portal.portlet.samples.SimplestHelloWorldPortlet
             </portlet-class>
             <supports>
             <mime-type>text/html</mime-type>
             </supports>
             <portlet-info>
             <title>Simplest Hello World Portlet</title>
             </portlet-info>
             </portlet>
            </portlet-app>


            default-object.xml

            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE deployments PUBLIC
             "-//JBoss Portal//DTD Portal Object 2.6//EN"
             "http://www.jboss.org/portal/dtd/portal-object_2_6.dtd">
            <deployments>
             <deployment>
             <parent-ref>default</parent-ref>
             <if-exists>overwrite</if-exists>
             <page>
             <page-name>SimplestHelloWorld</page-name>
             <window>
             <window-name>SimplestHelloWorldWindow</window-name>
             <instance-ref>SimplestHelloWorldInstance</instance-ref>
             <region>center</region>
             <height>0</height>
             </window>
             </page>
             </deployment>
            </deployments>


            • 3. Re: Portlet Instance Class Path
              peterj

               

              In addition, I have a WEB-INF/lib directory that contains the following jars: explode.jar, portal-common-lib.jar, and portlet-api-lib.jar I needed to add these jars for the class file.


              What are the portal-common-lib.jar, and portlet-api-lib.jar files? Do they provide the portlet (JSR-168) API? If so, remove them, the JBoss Portal already provides them. I do not recognize explode.jar, what functionality does it provide and how does your portlet require it?

              web.xml can be empty, like you have it

              Just noticed that you are using the 2.0 schem for thep ortlet.xml file. I think that schema is valid only for the newer portlet containers that support JSR-286. Try changing the schema to 1.0:

              <portlet-app
               xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation=
               "http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
               version="1.0">



              • 4. Re: Portlet Instance Class Path
                bsisson

                If originally left the jar files in the lib directory (I will explain below) and changed the version in the portal.xml file. I still got the same error "Failed to create instance...is not available".

                I then deleted the lib directory with the three jar files in it. I then get errors on my java code.

                package org.jboss.portal.portlet.samples;
                import java.io.IOException;
                import java.io.PrintWriter;
                import javax.portlet.GenericPortlet;
                import javax.portlet.RenderRequest;
                import javax.portlet.RenderResponse;
                
                public class SimplestHelloWorldPortlet extends GenericPortlet
                {
                 public void doView(RenderRequest request,
                 RenderResponse response) throws IOException
                 {
                 PrintWriter writer = response.getWriter();
                 writer.write("Hello World !");
                 writer.close();
                 }
                }


                The GenericPortlet and RenderREquest canot be resolved. These are probabaly in the JBoss Portal. However, I'm trying to build the project with Eclipse IDE and I need to reference a jar file to elimiante the errors to get a clean build. I looked in the JBoss server directory for the jar file to use and I was going to reference it in my Eclipse project to get it to build w/o errors. Can you please direct me to the correct jar file in the jboss-portal-2.6.6 version?

                • 5. Re: Portlet Instance Class Path
                  peterj

                  I include jboss-portal.sar/lib/portal-portlet-jsr168api-lib.jar.

                  This is one of the dangers of using a tool to help you when learning a new technology - you often spend more time working around issues with the tool than you you do actually learning about the technology.