
Fast Plugin Development
Table of Contents [-]
Save time by allowing developers to work with exploded plugin WARs instead of having to package them for deployment.
Create a context file #
The first thing to do is create a context file for the plugin, pointing to the exploded WAR: Create an xml file called like your plugin. For example, if your plugin is a portlet called something-portlet your file must be called something-portlet.xml and the content will be the following:
<Context path="foo" docBase="D:/Projects/liferay-plugins-sdk/portlets/foo-portlet/docroot" />
Deploy context file #
Once created just drop this file into the Liferay autodeploy directory. Liferay will copy this file to TOMCAT_DIR/conf/Catalina/localhost and the plugins will be registered. If the WAR was previously deployed, a new copy of the context file to the autodeploy directory will cause a redeploy of the exploded WAR. (If you had deployed your plugin before, it is advised to remove the old deployed application in webapps folder and restart Tomcat).
Copy dependencies #
You may probably need some libraries and tlds that were previously copied from the core. In order to know which ones you need, go to the webapps/somthing-portlet/WEB-INF folder and copy the lib and tld folders to your plugin WEB-INF folder too.
Using Fast Development in Tomcat #
From now on, if you change jsp files, they are modified when you refresh the page in your browser. For java classes and xml files you need to do ant compile from the plugin folder and copy again the context file into the Liferay autodeploy directory unless the Tomcat's context property "reloadable" is set to true. To do so, open the $TOMCAT_LIFERAY/conf/context.xml file and replace the line <Context> by <Context reloadable="true">. Then restart Tomcat. You can now update any part of the webapp (JSP, JSF pages... Java beans, servlets.... and they will automatically be reloaded by the Tomcat class loader).
Automating the configuration for fast development #
The steps outlined in the previous sections are valid for one portlet. If you are working with many portlets you may want to automate it so that the configuration is easily applied to any new portlet.
The following subsections explain how to achieve this by customizing the build scripts of the Plugins SDK
1) Extend the 'create' target #
Add the following quoted with EXPLODEDWARTEMPLATE inside the create target in the pluginsSDK\portlets\build.xml file:
<replace dir="${portlet.name}-portlet"> <replacefilter token="@portlet.name@" value="${portlet.name}" /> <replacefilter token="@portlet.display.name@" value="${portlet.display.name}" /> </replace> <!--<EXPLODEDWARTEMPLATE>--> <sequential> <antelope:stringutil string="${basedir}" property="pluginpath"> <antelope:replace regex="\\" replacement="/" /> </antelope:stringutil> <property name="plugincontextfile" value="${pluginpath}/${portlet.name}-portlet/${portlet.name}-portlet.xml" /> <copy file="${pluginpath}/EXPLODEDWARTEMPLATE-portlet.xml" tofile="${plugincontextfile}" /> <replace file="${plugincontextfile}"> <replacefilter token="@portlet.name@" value="${portlet.name}" /> <replacefilter token="@pluginpath@" value="${pluginpath}" /> </replace> </sequential> <!--<EXPLODEDWARTEMPLATE>--> <mkdir dir="${portlet.name}-portlet/docroot/WEB-INF/tld" />
2) Create a template Tomcat configuration file #
Create a file named EXPLODEDWARTEMPLATE-portlet.xml inside the pluginsSDK\portlets directory with the following content:
<?xml version="1.0"?> <Context path="@portlet.name@" docBase="@pluginpath@/@portlet.name@-portlet/docroot" />
3) Done #
Now you can run ant create for creating new portlets as usual and they will be created with 'fast development' preconfigured.
Other useful customizations #
Deployment of exploded WAR using ANT #
Add the following new target inside the pluginsSDK\portlets\build-common-portlet.xml file:
<target name="deploy-exploded" depends="compile"> <sequential> <antelope:stringutil string="${basedir}/${plugin.name}.xml" property="plugincontextfile"> <antelope:replace regex="\\" replacement="/" /> </antelope:stringutil> <copy file="${plugincontextfile}" todir="${auto.deploy.dir}" /> </sequential> </target>
Note that you also have to add the antelope prefix:
xmlns:antelope="antlib:ise.antelope.tasks"
Now, you could do a deploy of the exploded WAR using: ant deploy-exploded