Development in the ext environment
From LiferayPedia
- Categories
- Development
- Introduction to Liferay development
This guide explains how to do usual development tasks in the extension environment. It should be considered an extension to the Development in the Extension Environment Guide found in Liferay's Official Documentation] (section on Development). Be sure to check the documents that correspond to your version of Liferay.
Development is done in the /ext directory. When new versions of Liferay come out, the /portal directory can be replaced with the new version, and the /ext directory "updated" by re-running the build-ext target found in /portal/build.xml.
Any new jar files required by your extensions should be placed in /ext/ext-lib
WARNING: This article describes the versions from 4.0 to 4.2 of the extension environment. Version 4.3 has some changes that are documented in the Official Documentation]
Note: The default Language.properties file is located at /portal/portal-impl/classes/content/Language.properties. The Language-ext.properties file referred to in the docs is located at /ext/ext-impl/classes/content/Language-ext.properties
Contents[hide] |
Normal development process
Typically, customization/development need only occur inside the "extension environment." The normal development cycle from within the extension environment is:
- Ensure "extension environment" is set up (see the topic Setting up the Extension Environment)
- Customize portal properties by editing file /ext/ext-impl/classes/portal-ext.properties
- Customize settings in web.xml by adding entries to /ext/ext-web/docroot/WEB-INF/web.xml. (just put the fragments you want. The changes will be merged in to final web.xml by deployment process.
- Turn portlets you want to deploy on/off by editing /ext/ext-web/docroot/WEB-INF/liferay-portlet-ext.xml
- Customize language/display information by editing /ext/ext-impl/classes/content/Language-ext.properties or /ext/ext-impl/classes/content/Language-ext_en.properties(see Language/display customization)
- New classes to be made part of the core portal system should be created in /ext/ext-impl/src.
- To create an entirely new portlet, follow the directions here: http://content.liferay.com/4.0.0/docs/quickstart/ch04s02.html
- Run the "deploy" target from /ext/build.xml. This will merge all of the changes from above, build the system, and deploy to the configured application server (configured in /ext/app.server.<developerName>.properties file).
If developing a single portal instance, and customization is desireable, create, update, and/or modify files by placing them in the /ext/ext-web/docroot directory. When ready to deploy, call the "deploy" target in /ext/ext-web/build.xml. This will unjar the "default" web configuration from /ext/ext-ear/modules/portal-war, to a temporary directory, overwrite the temp dir with those file in /ext/ext-web/docroot, then deploy to the app server.
Customizing the Liferay Core
If customizing the core portal system (i.e. modifying the base Liferay source for consumption by the Liferay community), the development cycle is the following:
- Make your changes in the appropriate /portal/ source file (most interesting core stuff is in /portal/portal-impl/src)
- If adding a column to an entity, do NOT modify the XXXModel.java file, but add it to appropriate service.xml (see Services, entities, and ServiceBuilder)
- If adding a new method to one of the services, modify XXXServiceImpl.java or XXXLocalServiceImpl.java. Don't modify any of the other service interfaces (see Services, entities, and ServiceBuilder)
- If any mods are made in 1 and/or 2 above, run the "build-service-portal" and/or "build-service-portlets" target in /portal/portal-impl/build.xml to regenerate the code. See the "Services, entities, and ServiceBuilder" section below for details.
- Run the "start" target in /portal/build.xml (to rebuild the portal)
- Run the "build-ext" target in /portal/build.xml (to rebuild the extension environment, re-deploying the new changes from step 2 above).
This will rebuild the extension environment, but preserve all of your customized "*-ext.*" files. You can then deploy THOSE changes by re-running the "deploy" target in /ext/build.xml
Notes: In theory, multiple web sites can be developed concurrently by creating various site directories in /ext/web-sites/<domainName>-web. The "liferay.com-web" directory. All sites placed in this dir will have the various files from above merged in. liferay.com-web seems to be the target of this process. As of 4.1.x, however, it does not appear that the deployment process (i.e. the "deploy" target) recognizes any directories other than liferay.com-web.
Interesting tidbit: The liferay.com-web directory seems to be created in the /portal/ tree initially by info in the /portal/web-sites/web-sites.xml. web-sites.xml is used by com.liferay.portal.tools.WebSiteBuilder to build various sites under the /ext/web-sites dir.
Overriding JSP's from Liferay Core
JSP's from core can be easily customized/overridden by making a parallel change in the EXT environment. For example, if you want to modify the view.jsp of the login portlet, here are the steps:
- Locate the JSP code in the portal core (portal/portal-web/docroot/html/portlet/login/view.jsp)
- Copy the file to the corresponding location in the EXT environment (creating folders as necessary)
- Create the folder path: ext/ext-web/docroot/html/portlet/login/
- Copy the JSP from portal to ext: view.jsp
- Make desired changes to JSP in EXT environment
- Deploy changes
- Since we only made changes to JSP's, we can use the "deploy-fast" ant target in the build script of ext/ext-web/build.xml which will only deploy modified jsp's (very fast!).
Configuring Log4J logging
- Copy /portal/portal-impl/classes/META-INF/portal-log4j.xml to /ext/ext-impl/classes/META-INF/portal-log4j-ext.xml (i.e. copy from the /portal/portal-impl dir to the /ext/ext-impl, then rename to portal-log4j-ext.xml)
- Copy /portal/portal-impl/classes/META-INF/log4j.dtd to the same /ext/ext-impl/classes/META-INF dir as above
- Modify your new portal-log4j-ext.xml with whatever log4j parameters you want
- Deploy your extension environment
- Note that if you are deploying the portal under the Apache Geronimo application server, and you want to output DEBUG and TRACE messages, then may need to adjust the log4j Threshold default from INFO to DEBUG or TRACE. The Geronimo Console interface provides a feature whereby you can set the logging threshold at runtime via the browser. This is achieved by the following line in the var/log/server-log4j.properties file: log4j.appender.CONSOLE.Threshold=${org.apache.geronimo.log.ConsoleLogLevel}
Development shortcuts
Since development frequently involves frequent interations over the code/deploy/test/debug cycle, rebuilding the entire system, rolling it up to the extension environment, and re-deploying can quickly slow down productivity. Here are some development shortcuts you can use if your changes are isolated to a particular area of the code:
To modify anything located in /portal/portal-impl/
- Insure there is a customized /portal/app.server.<developerName>.properties file (may have to copy from the /ext/ directory
- modify the source code
- Execute the "deploy" target in /portal/portal-impl/build.xml
- repeat from step #2
To modify anything located in /portal/portal-web/
- Insure there is a customized /portal/app.server.<developerName>.properties file (may have to copy from the /ext/ directory
- modify the source code
- Execute the "war" target in /portal/portal-web/build.xml
- Execute the "build-ext" target in /portal/build.xml
- repeat from step #2
To modify any jsp's
- modify source code in {$App Server}/webapps/ROOT/html/
- refresh page
- repeat from step #1
- save code in ext-web/docroot/html before deploying from /ext/ext-web
another alternative is to use the 'deploy-fast' ant task in /portal/portal-web/build.xml. This will deploy any modified jsps only to your app server.
原出处:http://wiki.liferay.com/index.php/Development_in_the_ext_environment