Portal入门及Pluto1.0.1的安装
1. Pluto1.0.1的安装
首先从http://portals.apache.org/pluto/下载pluto-1.0.1-rc1.zip,
新建一目录,如D:\Portal把刚下载的pluto-1.0.1-rc1.zip文件解压在其下,展开目录为pluto-1.0.1-rc1
执行D:\Portal\pluto-1.0.1-rc1\bin\startup.bat启动Pluto,
现在可以通过地址http://localhost:8080/pluto/portal访问Pluto服务器。
2.编写并部署HelloPortlet
在D:\Portal目录下新建一目录,如works,作为工作目录,在其下新建一子目录myapp1
建立如下目录结构:
myapp1
|---src
|---lib
|---web
|---WEB-INF
|---build.xml
|---build.properties
其中build.xml的内容如下:
<project name="myapp1" default="help" basedir=".">
<!-- ===================== Property Definitions =========================== -->
<!--
All properties should be defined in this section.
Any host-specific properties should be defined
in the build.properties file.
In this app, the following properties are defined in build.properties:
o tomcat.home - the home directory of your Tomcat installation
o webapps.home - the place to copy the war file to deploy it
-->
<property file="build.properties" />

<property name="app.home" value="." />
<property name="app.name" value="myapp1" />
<property name="javadoc.pkg.top" value="myapp1" />
<property name="src.home" value="${app.home}/src"/>
<property name="lib.home" value="${app.home}/lib"/>
<property name="classes.home" value="${app.home}/classes"/>
<property name="deploy.home" value="${app.home}/deploy"/>
<property name="doc.home" value="${app.home}/doc"/>
<property name="web.home" value="${app.home}/web"/>
<property name="build.home" value="${app.home}/build"/>
<property name="build.classes" value="${build.home}/WEB-INF/classes"/>
<property name="build.lib" value="${build.home}/WEB-INF/lib"/>
<!-- ==================== Compilation Classpath =========================== -->
<!--
This section creates the classpath for compilation.
-->
<path id="compile.classpath">
<!-- The object files for this application -->
<pathelement location="${classes.home}"/>
<!-- The lib files for this application -->
<fileset dir="${lib.home}">
<include name="*.jar"/>
<include name="*.zip"/>
</fileset>
<!-- All files/jars that Tomcat makes available -->
<fileset dir="${tomcat.home}/common/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${tomcat.home}/shared/lib">
<include name="*.jar"/>
</fileset>
<pathelement location="${tomcat.home}/common/classes"/>
</path>

<!-- ==================== Build Targets below here========================= -->

<!-- ==================== "help" Target =================================== -->
<!--
This is the default ant target executed if no target is specified.
This helps avoid users just typing 'ant' and running a
default target that may not do what they are anticipating...
-->
<target name="help" >
<echo message="Please specify a target! [usage: ant <targetname>]" />
<echo message="Here is a list of possible targets: "/>
<echo message=" clean-all.....Delete build dir, all .class and war files"/>
<echo message=" prepare.......Creates directories if required" />
<echo message=" compile.......Compiles source files" />
<echo message=" build.........Build war file from .class and other files"/>
<echo message=" deploy........Copy war file to the webapps directory" />
<echo message=" javadoc.......Generates javadoc for this application" />
</target>
<!-- ==================== "clean-all" Target ============================== -->
<!--
This target should clean up any traces of the application
so that if you run a new build directly after cleaning, all
files will be replaced with what's current in source control
-->
<target name="clean-all" >
<delete dir="${build.home}"/>
<delete dir="${classes.home}"/>
<delete dir="${deploy.home}"/>
<!-- can't delete directory if Tomcat is running -->
<delete dir="${webapps.home}/${app.name}" failonerror="false"/>
<!-- deleting the deployed .war file is fine even if Tomcat is running -->
<delete dir="${webapps.home}/${app.name}.war" />
<!-- delete the javadoc -->
<delete dir="${doc.home}"/>
</target>
<!-- ==================== "prepare" Target ================================ -->
<!--
This target is executed prior to any of the later targets
to make sure the directories exist. It only creates them
if they need to be created....
Other, similar, preparation steps can be placed here.
-->
<target name="prepare">
<echo message="Tomcat Home = ${tomcat.home}" />
<echo message="webapps Home = ${webapps.home}" />
<mkdir dir="${classes.home}"/>
<mkdir dir="${deploy.home}"/>
<mkdir dir="${doc.home}"/>
<mkdir dir="${doc.home}/api"/>
<mkdir dir="${build.home}"/>
<mkdir dir="${build.home}/WEB-INF" />
<mkdir dir="${build.home}/WEB-INF/classes" />
<mkdir dir="${build.home}/WEB-INF/lib" />
</target>
<!-- ==================== "compile" Target ================================ -->
<!--
This only compiles java files that are newer
than their corresponding .class files.
-->
<target name="compile" depends="prepare" >
<javac srcdir="${src.home}" destdir="${classes.home}" debug="yes" >
<classpath refid="compile.classpath"/>
</javac>
</target>
<!-- ==================== "build" Target ================================== -->
<!--
This target builds the war file for the application
by first building the directory structure of the
application in ${build.home} and then creating the
war file using the ant <war> task
-->
<target name="build" depends="compile" >
<!-- Copy all the webapp content (jsp's, html, tld's, xml, etc. -->
<!-- Note that this also copies the META-INF directory -->
<copy todir="${build.home}">
<fileset dir="${web.home}"/>
</copy>
<!-- Now, copy all the Java class files -->
<copy todir="${build.home}/WEB-INF/classes">
<fileset dir="${classes.home}"/>
</copy>
<!-- Now, copy all the properties files, etc that go on the classpath -->
<copy todir="${build.home}/WEB-INF/classes">
<fileset dir="${src.home}">
<include name="**/*.properties" />
<include name="**/*.prop" />
</fileset>
</copy>
<!-- Now, copy all the jar files we need -->
<copy todir="${build.home}/WEB-INF/lib">
<fileset dir="${lib.home}" />
</copy>
<!-- Create the <war> file -->
<jar jarfile="${deploy.home}/${app.name}.war"
basedir="${build.home}"/>
</target>
<!-- ==================== "deploy" Target ================================= -->
<!--
This target simply copies the war file from the deploy
directory into the Tomcat webapp directory.
-->
<target name="deploy" depends="build" >
<!-- Copy the contents of the build directory -->
<copy todir="${webapps.home}" file="${deploy.home}/${app.name}.war" />
</target>
<!-- ==================== "doc" Target ==================================== -->
<!--
This task creates javadoc. It is dependent upon only the
'compile' target so it is not executed in a normal build.
As a result, the target needs to be run on its own.
-->
<target name="javadoc" depends="compile">
<javadoc sourcepath = "${src.home}"
destdir = "${doc.home}/api"
packagenames = "${javadoc.pkg.top}.*"/>
</target>[来源 www.iocblog.net]
</project>
build.properties内容如下
| tomcat.home=D:/Portal/pluto-1.0.1-rc1 webapps.home=D:/Portal/pluto-1.0.1-rc1/webapps |
编写HelloPortlets代码如下:

/**//*
* HelloPortlet2.java
*
* Created on 2006年8月14日, 上午9:52
*/
package com.ceun.app;
import javax.portlet.*;
import java.io.*;
import java.util.logging.*;

/** *//**
*
* @author avk
*/
public class HelloPortlet2 extends javax.portlet.GenericPortlet ...{

public void init() ...{
System.out.println("Portlet2 in myapp1::init");
}

public void render() ...{
System.out.println("Portlet2 in myapp1::render");
}
public void processAction(ActionRequest request, ActionResponse actionResponse)
throws PortletException, java.io.IOException ...{
System.out.println("Portlet2 in myapp1::processRequest");
}
public void doView(RenderRequest req, RenderResponse res)
throws PortletException, IOException ...{
System.out.println("Portlet2 in myapp1::doView");
req.setAttribute("test", "String set by SamplePortlet::processAction");
res.setContentType("text/html");
String jspName = "/jsp/hello.jsp";
PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher(jspName);
rd.include(req, res);
}
public void doEdit(RenderRequest req, RenderResponse res)
throws PortletException, IOException ...{
System.out.println("Portlet2 in myapp1::doEdit");
/**//*
res.setContentType("text/html");
String jspName = "blah.jsp";
PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("blah.jsp");
rd.include(req, res);
*/
}
public void doHelp(RenderRequest req, RenderResponse res) ...{
System.out.println("Portlet2 in myapp1::doHelp");
/**//*
res.setContentType("text/html");
String jspName = "blah.jsp";
PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("blah.jsp");
rd.include(req, res);
*/
}
}
在web/WEB-INF目录下新建一portlet.xml文件内容如下:
[来源 www.iocblog.net]
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at 
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">

<portlet>
<description>My Portlet App</description>
<portlet-name>HelloPortlet2</portlet-name>
<display-name>My Portlet</display-name>
<portlet-class>com.ceun.app.HelloPortlet2</portlet-class>
<!--
<init-param>
<name>TestParameter</name>
<value>TestValue</value>
</init-param>
-->
<expiration-cache>-1</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
<portlet-mode>EDIT</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<portlet-info>
<title>HelloPortlet2</title>
<short-title>HelloPortlet2</short-title>
<keywords>Hello</keywords>
</portlet-info>
<!--
<portlet-preferences>
<preference>
<name>inget</name>
<value>inget</value>
<read-only>false</read-only>
</preference>
</portlet-preferences>
-->
</portlet>
</portlet-app>
在web/WEB-INF目录下新建web.xml文件,内容如下
<?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>
<servlet>
<!-- Make sure to use the same servlet name here as you do in the
corresponding servlet mapping. Create one servlet declaration
for each portlet. -->
<servlet-name>MyPortletServlet</servlet-name>
<!-- Don't change -->
<servlet-class>org.apache.pluto.core.PortletServlet</servlet-class>
<init-param>
<param-name>portlet-class</param-name>
<!-- Enter the class that implements the portlet -->
<param-value>com.ceun.app.HelloPortlet2</param-value>
</init-param>
<init-param>
<param-name>portlet-guid</param-name>
<!-- Enter the path to the portlet: the context path plus
the portlet name -->
<param-value>myapp1.HelloPortlet2</param-value>
</init-param>
</servlet>
<!-- Use the same name as in the servlet element -->
<servlet-mapping>
<servlet-name>MyPortletServlet</servlet-name>
<url-pattern>/MyPortlet2/*</url-pattern>
</servlet-mapping>
</web-app>
在web/WEB-INF目录下新建tld目录,在其中新建一portlet.tld文件,内容如下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at 
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<taglib>
<tlib-version>1.1</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>portlet</short-name>
<uri>http://java.sun.com/portlet</uri>
<display-name>Portlet Tags</display-name>
<description></description>
<tag>
<name>defineObjects</name>
<tag-class>org.apache.pluto.tags.DefineObjectsTag</tag-class>
<tei-class>org.apache.pluto.tags.DefineObjectsTag$TEI</tei-class>
<body-content>empty</body-content>
<display-name></display-name>
</tag>
<tag>
<name>param</name>
<tag-class>org.apache.pluto.tags.ParamTag</tag-class>
<body-content>empty</body-content>
<display-name></display-name>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
<tag>
<name>actionURL</name>
<tag-class>org.apache.pluto.tags.ActionURLTag</tag-class>
<tei-class>org.apache.pluto.tags.BasicURLTag$TEI</tei-class>
<body-content>JSP</body-content>
<display-name></display-name>
<attribute>
<name>windowState</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>portletMode</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>secure</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
<tag>
<name>renderURL</name>
<tag-class>org.apache.pluto.tags.RenderURLTag</tag-class>
<tei-class>org.apache.pluto.tags.BasicURLTag$TEI</tei-class>
<body-content>JSP</body-content>
<display-name></display-name>
<attribute>
<name>windowState</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>portletMode</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>secure</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
<tag>
<name>namespace</name>
<tag-class>org.apache.pluto.tags.NamespaceTag</tag-class>
<body-content>empty</body-content>
<display-name></display-name>
</tag>
</taglib>在myapp1目录下新建一jsp目录,在其下新建一hello.jsp文件,内容如下

<%...@page contentType="text/html" session="false"%>
<%...@page pageEncoding="utf-8"%>
<%...@page import="javax.portlet.*"%>
<%...@taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<portlet:defineObjects/>
<h4>Hello World!</h4>
<p>Good ok.</p>修改D:\Portal\pluto-1.0.1-rc1\webapps\pluto\WEB-INF\data目录下的portletentityregistry.xml文件
添加如下内容:
| <application id="5"> <definition-id>myapp1</definition-id> <portlet id="1"> <definition-id>myapp1.HelloPortlet2</definition-id> </portlet> </application> |
修改D:\Portal\pluto-1.0.1-rc1\webapps\pluto\WEB-INF\data目录下的pageregistry.xml文件
添加如下内容:
| <fragment name="myapp1" type="page"> <navigation> <title>ceun's Portlet</title> <description>Portlet From java619</description> </navigation> <fragment name="row4" type="row"> <fragment name="col5" type="column"> <fragment name="p1" type="portlet"> <property name="portlet" value="5.1"/> </fragment> </fragment> </fragment> </fragment> |
好,现在就可以编译并部署HelloPortlets了
重新启动Pluto
进入命令行,转到D:\Portal\works\myapp1目录下,执行ant deploy命令进行部署
现在可以通过地址http://localhost:8080/pluto/portal访问HelloPortlet了
文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。