From Liferay 6 portlets need to build using plugin SDK. Download PluginSDK, which is a separate download along with Liferay source.
Here are the steps to build portlets in Liferay 6.
1. Download Liferay-tomcat bundle, liferay-plugins-sdk-6.0.5.zip and liferay-portal-src-6.0.5.zip.
2. Extract liferay-tomcat bundle into "liferay-portal" dir. I am extracting this files into e:/liferay-portal-6.0.5
3. extract liferay-portal-src-6.0.5 and liferay-plugins-sdk-6.0.5.zip into this folder.
4. go to liferay-plugins-sdk-6.0.5 and edit build.properties file
app.server.dir=e:/liferay-portal-6.0.5/tomcat-6.0.29
5. go to folder E:\liferay-portal-6.0.5\liferay-plugins-sdk-6.0.5\portlets and execure
create.bat myPortlet "Myportlet"
6. A folder called "MyPortlet-portlet" would be created
7. configure eclipse project settings for this directory by going into this directoy and executing
ant setup-eclipse
8. Import this folder into eclipse
9. Execute ant deploy.
And your running tomcat instance should hot deploy it.
The portlet created is instance of MVCPortlet and should be available in "Samples" section.
Now the tricky part. The eclipse portlet project does not have any place to add java source files. Infact the eclipse project created is not a Java project and .classpath file is not available as well. You need to convert this project into Java project if you want to customize your portlet further.
1. Convert the project created by setup-eclipse command into Java Project.
Edit thre .project file. This is an XML file.
Replace buildSpec and natures of .project file with the following snippet
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
add a .classpath file and with the following snippet
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>
Close and reopen the project.
2. add source
create a source folder called "src"
3. Configure the bin-output to WEB-INF/classes
go to project-properties-->Source-->DefaultOutput folder
click the browse button and set this as WEB-INF classes.
Refresh the project.
4. Add required jars in the class path.
The following jars from E:\liferay-portal-6.0.5\portal-src\util** folders and TOMCAT/lib/ext folders have to be added.
util-bridges.jar, util-java.jar, util-taglibs.jar, portlet.jar, portal-service.jar.
5. Create a class called MyPortlet.java
Override the doView method. You can put some SOP and set some attributes to renderRequest.
6. Update the portlet-class to MyPortlet in portlet.xml.
7. Now you can read and display the value set in renderRequest in view.jsp.
No comments:
Post a Comment