Skip to content
topolik edited this page Oct 8, 2010 · 1 revision

Creating Project Structure

The easiest way to create the project is to download extlet-ant-sdk and unzip where you want.

Now you can create new extlet calling simply ant command in the extlet-ant-sdk directory:

cd extlet-ant-sdk
ant

Here you need to give name to your extlet and specify version (its your plugin version – nothing to do with extlets or liferay):

Buildfile: build.xml
-get-extlet-name:
    [input] How would you like to name you new extlet? [my-extlet]
my-new-extlet
    [input] Version of your my-new-extlet? [1.0]
1.0
-unzip-extlet:
    [unzip] Expanding: /tmp/extlet-ant-sdk/extlet-ant-project-template.zip into /tmp/extlet-ant-sdk/my-new-extlet

-init-build-properties:
-init-index-jsp:
create-extlet:
BUILD SUCCESSFUL
Total time: 9 seconds

Now edit extlet-ant-sdk/build.properties and specify location of your Tomcat with Liferay:

tomcat.dir=/data/opt/liferay-portal-5.2.3/tomcat-6.0.18

	
  1. -———————— DO-NOT-MODIFY SECTION -————————

And that’s all.

Understanding Project Structure

.
./war
./war/src
./war/src/main
./war/src/main/java
./war/src/main/resources
./war/src/main/webapp
./war/src/main/webapp/WEB-INF
./war/src/main/webapp/WEB-INF/liferay-hook.xml
./war/src/main/webapp/WEB-INF/liferay-plugin-package.properties
./war/src/main/webapp/WEB-INF/liferay-extlet.properties
./war/src/main/webapp/WEB-INF/web.xml
./war/src/main/webapp/index.jsp
./build.xml
./build.properties
./extlet-impl
./extlet-impl/src
./extlet-impl/src/main
./extlet-impl/src/main/java
./extlet-impl/src/main/resources
./extlet-impl/src/main/resources/META-INF
./extlet-impl/src/main/resources/META-INF/extlet-tiles-defs.xml
./extlet-impl/src/main/resources/META-INF/extlet-model-hints.xml
./extlet-impl/src/main/resources/META-INF/extlet-remoting-servlet.xml
./extlet-impl/src/main/resources/META-INF/extlet-spring.xml
./extlet-impl/src/main/resources/META-INF/liferay-portlet-extlet.xml
./extlet-impl/src/main/resources/META-INF/portlet-extlet.xml
./extlet-impl/src/main/resources/META-INF/extlet-hbm.xml
./extlet-impl/src/main/resources/META-INF/extlet-portal.properties
./extlet-impl/src/main/resources/META-INF/extlet-struts-config.xml
./extlet-impl/src/main/resources/META-INF/service.xml
./extlet-impl/src/main/resources/content
./extlet-impl/src/main/resources/content/Language-extlet.properties
./extlet-impl/src/main/resources/content/Language-extlet_cs.properties
./extlet-service
./extlet-service/src/main/java
./extlet-service/src/main/resources

In the project structure there are 3 main directories:

  • extlet-impl – subproject for the portal-impl changes
  • extlet-service – subproject for the portal-service changes
  • war – encapsulating web application, where portlets and/or hooks can be created

extlet-impl and extlet-service directory

To override sources in the portal-impl source directory (for example some struts action), you can place the file into the project this way:

./extlet-impl/src/main/java/com/liferay/portlet/admin/action/EditServerAction.java

The same way you can add/override portal-service sources.

war directory

This Maven project contains the extlet-impl and extlet-service jars, which will be placed into the container with Liferay.

Because this project is simple web application (just like any other), you can place here hook or portlets. For more information please see the All-in-one Concept and Adding Hooks and Portlets.

This war to be recognized by the Extlet environment must contain the ./war/src/main/webapp/WEB-INF/liferay-extlet.properties file, which contains specification of where the portal-impl.jar and portal-service.jar are located.

Compiling & Packaging

To compile your project you just have to enter your Extlet application, e.g. cd my-new-extlet/ and call

ant clean dist

The log tells you where the assembled war is:

Buildfile: build.xml
clean:
init:
    [mkdir] Created dir: /tmp/extlet-ant-sdk/my-new-extlet/build/impl
    [mkdir] Created dir: /tmp/extlet-ant-sdk/my-new-extlet/build/service
    [mkdir] Created dir: /tmp/extlet-ant-sdk/my-new-extlet/build/war/WEB-INF/classes
    [mkdir] Created dir: /tmp/extlet-ant-sdk/my-new-extlet/build/war/WEB-INF/lib
    [mkdir] Created dir: /tmp/extlet-ant-sdk/my-new-extlet/dist
build-service:
build-impl:
     [copy] Copying 12 files to /tmp/extlet-ant-sdk/my-new-extlet/build/impl
build-war:
     [copy] Copying 5 files to /tmp/extlet-ant-sdk/my-new-extlet/build/war
dist-service:
      [jar] Building MANIFEST-only jar: /tmp/extlet-ant-sdk/my-new-extlet/dist/extlet-service-my-new-extlet-jar-1.0.jar
dist-impl:
      [jar] Building jar: /tmp/extlet-ant-sdk/my-new-extlet/dist/extlet-impl-my-new-extlet-jar-1.0.jar
dist-war:
     [copy] Copying 2 files to /tmp/extlet-ant-sdk/my-new-extlet/build/war/WEB-INF/extlet-lib
      [war] Building war: /tmp/extlet-ant-sdk/my-new-extlet/dist/my-new-extlet-war.war
dist:
BUILD SUCCESSFUL
Total time: 0 seconds

Deploying

Copy the war file from ./dist/ directory into the auto-deploy directory of the Tomcat, e.g.:

cp /tmp/extlet-ant-sdk/my-new-extlet/dist/my-new-extlet-war.war /data/opt/liferay-portal-5.2.3/deploy/

Now you can see the Liferay’s log file:

15:36:11,316 INFO  [AutoDeployDir:183] Processing my-new-extlet-war.war
15:36:11,321 INFO  [PortletAutoDeployListener:67] Deploying package as a web application
15:36:11,390 INFO  [PortletAutoDeployListener:77] Copying portlets for /data/opt/liferay-portal-5.2.3/deploy/my-new-extlet-war.war
  Expanding: /data/opt/liferay-portal-5.2.3/deploy/my-new-extlet-war.war into /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/temp/20101008153611395
  Copying 1 file to /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/temp/20101008153611395/WEB-INF/classes
  Copying 1 file to /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/temp/20101008153611395/WEB-INF/classes
  Copying 1 file to /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/temp/20101008153611395/META-INF
  Copying 1 file to /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/temp/20101008153611395/WEB-INF
  Copying 1 file to /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/temp/20101008153611395/WEB-INF
  Copying 1 file to /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/temp/20101008153611395/WEB-INF
  Copying 1 file to /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/temp/20101008153611395/WEB-INF/jsp/liferay/wai
  Copying 1 file to /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/temp/20101008153611395/WEB-INF/jsp/liferay/wai
  Warning: META-INF/MANIFEST.MF modified in the future.
  Warning: WEB-INF/extlet-lib/extlet-impl-my-new-extlet-jar-1.0.jar modified in the future.
  Warning: WEB-INF/extlet-lib/extlet-service-my-new-extlet-jar-1.0.jar modified in the future.
  Warning: WEB-INF/liferay-extlet.properties modified in the future.
  Warning: WEB-INF/liferay-plugin-package.properties modified in the future.
  Warning: index.jsp modified in the future.
  Warning: WEB-INF/extlet-lib modified in the future.
  Copying 27 files to /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/webapps/my-new-extlet-war
  Copying 1 file to /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/webapps/my-new-extlet-war
  Deleting directory /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/temp/20101008153611395
15:36:12,069 INFO  [PortletAutoDeployListener:87] Portlets for /data/opt/liferay-portal-5.2.3/deploy/my-new-extlet-war.war copied successfully. Deployment will start in a few seconds.
15:36:13,916 INFO  [HookHotDeployListener:184] Registering hook for my-new-extlet-war
15:36:13,920 INFO  [HookHotDeployListener:379] Hook for my-new-extlet-war is available for use
15:36:13,924 INFO  [PortletHotDeployListener:227] Registering portlets for my-new-extlet-war
15:36:14,217 INFO  [PortletHotDeployListener:346] 1 portlet for my-new-extlet-war is available for use
15:36:14,229 INFO  [ExtletHotDeployer:106] Extlet my-new-extlet-war has been succesfully deployed
15:36:14,229 INFO  [ExtletHotDeployer:110] Restart is needed. Restart should start in a few seconds ... 

If you have the Hot Deploy Feature enabled, you should see:

13:20:38,590 WARN  [TomcatRestarter:322] Reloading Root WebModule ...
May 4, 2010 1:20:38 PM org.apache.catalina.core.StandardContext reload   
INFO: Reloading this Context has started              
...
13:21:16,489 WARN  [TomcatRestarter:344] Reloading Root WebModule finished
13:21:16,489 INFO  [TomcatRestarter:163] Restart took 37899 ms

Otherwise you’ll see the following message and you have to reboot the Tomcat for your application to load:

13:26:28,931 WARN  [TomcatRestarter:69] TomcatHostRestart is disabled. Please restart the Tomcat manually!

Service Builder
Ant environment supports service builder.

To use Service Builder, please modify ./extlet-impl/src/main/resources/META-INF/service.xml file.

Then you can run ant service-builder which generates services into extlet-service directory and implementation into extlet-impl directory. SQL files can be found in ./extlet-impl/src/main/resources/META-INF/sql directory:

Buildfile: build.xml
init:
service-builder:
    [mkdir] Created dir: /tmp/extlet-ant-sdk/my-new-extlet/build/service-builder-temp
    [mkdir] Created dir: /tmp/extlet-ant-sdk/my-new-extlet/extlet-impl/src/main/resources/sql
     [java] Loading jar:file:/data/opt/liferay-portal-5.2.3/tomcat-6.0.18/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
     [java] Loading jar:file:/data/opt/liferay-portal-5.2.3/tomcat-6.0.18/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
     [java] Loading jar:file:/data/opt/liferay-portal-5.2.3/tomcat-6.0.18/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties
     [java] Loading jar:file:/data/opt/liferay-portal-5.2.3/tomcat-6.0.18/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/captcha.properties
     [java] 15:39:04,313 INFO  [PortalImpl:252] Portal lib directory /data/opt/liferay-portal-5.2.3/tomcat-6.0.18/webapps/ROOT/WEB-INF/lib/
     [java] Building UserAttributes
     [java] Writing extlet-impl/src/main/java/com/liferay/portal/service/persistence/UserAttributesPersistenceImpl.java
     [java] Writing extlet-service/src/main/java/com/liferay/portal/service/persistence/UserAttributesPersistence.java
     [java] Writing extlet-service/src/main/java/com/liferay/portal/service/persistence/UserAttributesUtil.java
     [java] Writing extlet-impl/src/main/java/com/liferay/portal/model/impl/UserAttributesModelImpl.java
     [java] Writing extlet-impl/src/main/java/com/liferay/portal/model/impl/UserAttributesImpl.java
     [java] Writing extlet-service/src/main/java/com/liferay/portal/model/UserAttributesModel.java
     [java] Writing extlet-service/src/main/java/com/liferay/portal/model/UserAttributes.java
     [java] Writing extlet-service/src/main/java/com/liferay/portal/model/UserAttributesSoap.java
     [java] Writing extlet-impl/src/main/java/com/liferay/portal/service/impl/UserAttributesLocalServiceImpl.java
     [java] Writing extlet-impl/src/main/java/com/liferay/portal/service/base/UserAttributesLocalServiceBaseImpl.java
     [java] Writing extlet-service/src/main/java/com/liferay/portal/service/UserAttributesLocalService.java
     [java] Writing extlet-service/src/main/java/com/liferay/portal/service/UserAttributesLocalServiceUtil.java
   [delete] Deleting directory /tmp/extlet-ant-sdk/my-new-extlet/build/service-builder-temp
BUILD SUCCESSFUL
Total time: 5 seconds

Now you can build your application using ant dist or ant clean dist as usual.


Next: Adding Hooks and Portlets