1.      从Liferay官方网站www.liferay.com下载安装文件liferay-portal-pro-3.2.0-tomcat.zip

 

在D盘创建liferayPro目录,解压缩liferay-portal-pro-3.2.0-tomcat.zip到D:\liferayPro\liferay-portal-pro-3.2.0-tomcat

设置环境变量$CATALINA_HOME= D:\liferayPro\liferay-portal-pro-3.2.0-tomcat

 

2.      安装test.war

--------------以下引用liferay.com资料

Hot Deploy Portlet WARs

 

Liferay allows you to easily hot deploy JSR 168 compliant portlets. The following instructions deal with setting up your environment to use Ant to deploy the Test portlet or other JSR 168 compliant portlets.

 

  • Create a portlets directory called /my_portlets.  
  • Download test.war into /my_portlets. This WAR contains sample JSP and Struts portlets. You can also expand the WAR into /my_portlets/test.war to deploy an expanded WAR.

    Download portletsamples.war from Sun into /my_portlets. All of the portlets work except for the Weather Portlet because it requires JSP 1.2 and some of the application servers that Liferay supports do not yet support JSP 1.2.

    Download build.xml into /my_portlets. Make sure Ant 1.6.2 and JDK 1.4.2 is set up properly. See Development Environment for instructions on setting up Ant and JDK.  
  • Install either JBoss+Jetty, JBoss+Tomcat, Jetty, or Tomcat.

    Edit build.xml to point to your application server or servlet container. For example, if you installed Tomcat to  /liferay, edit build.xml to make sure that only the Tomcat section is uncommented and set the property app.server.dir to liferay.

下载的build.xml文件并不一定能用,在这个例子里需要修改成如下:

 

<?xml version="1.0"?>
 <project name="portlets" basedir="." default="deploy">
 <target name="init">
 <property environment="env" />
 <property name="app.server.type" value="tomcat" />
 <property name="app.server.dir" value="/liferayPro/liferay-portal-pro-3.2.0-tomcat" />
 <property name="app.server.deploy.dir" value="${app.server.dir}/webapps" />
 <path id="project.classpath">
 <pathelement location="${env.ANT_HOME}/lib/ant.jar" />
 <fileset dir="${app.server.dir}/common/lib/ext" />
 <pathelement location="${app.server.dir}/common/lib/servlet-api.jar" />
 </path>
 </target>

 <target name="deploy" depends="init">

  <java classname="com.liferay.portal.tools.PortletDeployer" classpathref="project.classpath" fork="true"

   newenvironment="true">

   <!-- Required Arguments -->

  
 <jvmarg value="-Dportlet.deployer.base.dir=./" />

 <jvmarg value="-Dportlet.deployer.dest.dir=${app.server.deploy.dir}" />

  <jvmarg value="-Dportlet.deployer.app.server.type=${app.server.type}" />
 <jvmarg value="-Dportlet.deployer.taglib.dtd=${app.server.dir}/liferay/WEB-INF/tld/liferay-portlet.tld" />

 <!-- Optional Arguments -->

  

  
 <jvmarg value="-Dportlet.deployer.jboss.prefix=1" />

   <jvmarg value="-Dportlet.deployer.tomcat.lib.dir=${app.server.dir}/common/lib/ext" />
 <!-- Dependent Libraries -->

   <arg value="${app.server.dir}/liferay/WEB-INF/lib/util-taglib.jar" />

   <arg value="${app.server.dir}/common/lib/util-java.jar" />

   </java>

  

 </target>

  

 </project> 




 

3.      安装Ant

下载Ant安装文件 http://ant.apache.org

解压缩到D:\ant\apache-ant-1.6.2

设置环境变量$ANT_HOME= D:\ant\apache-ant-1.6.2

增加 $ANT_HOME/bin 到 环境变量$PATH中

 

4.      进入到my_portlets 文件夹(假设在D:\liferayPro\),在Dos窗口下运行ant deploy命令。Ant 会根据build.xml中的设置把test.war部署到D:\liferayPro\liferay-portal-pro-3.2.0-tomcat\webapps\目录下

输出信息如下:


D:\liferayPro\my_portlets>ant deploy 
 
Buildfile: build.xml 
 
 
init: 
 
 
deploy: 
 
 
     [java] Deploying test.war 
 
     [java]   Expanding: .\test.war into 20050625121028802 
 
     [java]   Modifying 20050625121028802\WEB-INF\web.xml 
 
     [java]   Copying 69 files to D:\liferayPro\liferay-portal-pro-3.2.0-tomcat\webapps\test 
 
     [java]   Deleting directory D:\liferayPro\my_portlets\20050625121028802 
 
 
BUILD SUCCESSFUL 
 
Total time: 3 seconds 
 
D:\liferayPro\my_portlets>

 

5.      启动 liferay server

D:\liferayPro\liferay-portal-pro-3.2.0-tomcat\bin\startup.bat

 

6.      测试test.war是否安装成功

1)打开IE,输入http://localhost

2)用户:test@liferay.com 密码:test

3)点击Home

4)查看屏幕下方的下拉框中是否存在Test JSP和Test Struts

5)选中Test JSP,点击Add按钮,如果Test JSP portlet正确显示说明test.war安装好了

 

7.      接下来我们要创建一个自己的portlet -mytest

 

8.      新建一个jsp文件welcome.jsp

D:\liferayPro\liferay-portal-pro-3.2.0-tomcat\webapps\test\html\portlet\test_jsp\welcome.jsp

welcome.jsp内容如下:



<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

  

  

 <portlet:defineObjects />

  

  

 <table cellpadding="8" cellspacing="0" width="100%">

  

 <tr>

  

 <td>

  

            <font class="gamma" size="2">

  

            Welcome to My Test Protlet

  

            </font>

  

 </td>

   

</tr>

  

 </table>


修改D:\liferayPro\liferay-portal-pro-3.2.0-tomcat\webapps\test\WEB-INF\liferay-portlet.xml

粗体部分为要增加的portlet。


<?xml version="1.0"?>

  

 <!DOCTYPE portlets PUBLIC "-//Liferay//DTD PORTLET 2.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet_2_2_0.dtd">

  

  

 <portlets>

  

 <portlet id="test_jsp" struts-path="test_jsp" use-default-template="true" />

  

 <portlet id="test_struts" struts-path="test_struts" use-default-template="true" restore-current-view="true" />

  

 <portlet id="mytest_welcome" struts-path="mytest_welcome" use-default-template="true" />

  

 <custom-user-attribute name="user.name.test" custom-class="com.liferay.portlet.teststruts.TestStrutsUserAttributes" />

  

 </portlets>

10.  修改D:\liferayPro\liferay-portal-pro-3.2.0-tomcat\webapps\test\WEB-INF\portel.xml

增加以下内容到portlet.xml文件中

 

<portlet> 
 
           <portlet-name>mytest_welcome</portlet-name> 
 
           <display-name>My Test Welcome</display-name> 
 
           <portlet-class>com.liferay.portlet.JSPPortlet</portlet-class> 
 
           <init-param> 
 
                    <name>view-jsp</name> 
 
                    <value>/portlet/test_jsp/welcome.jsp</value> 
 
           </init-param> 
 
           <expiration-cache>0</expiration-cache> 
 
           <supports> 
 
                    <mime-type>text/html</mime-type> 
 
           </supports> 
 
           <portlet-info> 
 
                    <title>Welcome to My Test Portlet</title> 
 
                    <short-title>MyTest</short-title> 
 
                    <keywords>MyTest</keywords> 
 
           </portlet-info> 
 
           <security-role-ref> 
 
                    <role-name>Guest</role-name> 
 
           </security-role-ref> 
 
           <security-role-ref> 
 
                    <role-name>Power User</role-name> 
 
           </security-role-ref> 
 
           <security-role-ref> 
 
                    <role-name>User</role-name> 
 
           </security-role-ref> 
 
</portlet>

 

11.  修改D:\liferayPro\liferay-portal-pro-3.2.0-tomcat\webapps\test\WEB-INF\liferay-display.xml

增加以下内容:

 

<display> 
 
<category name="category.mytest"> 
 
           <portlet id="mytest_welcome" /> 
 
</category> 
 
</display>

 

 

12.  由于Liferay Portal Server采用的是ASP模式,一个服务器可以部署多个公司的Protal。在D:\liferayPro\liferay-portal-pro-3.2.0-tomcat\webapps\test\WEB-INF\web.xml中可是设置test.war属于哪个公司,这里我们不改变web.xml的内容

<web-app>

 

<display-name>test</display-name> 
 
<context-param> 
 
           <param-name>company_id</param-name> 
 
           <param-value>liferay.com</param-value> 
 
</context-param> 
 
………….. 
 
</web-app>

 

 

13.  重复第6步,看看下拉框中是否存在Welcome to My Test Portlet