为不同的liferay portlet开发一个通用的jar库 [英] Develop a common jar library for different liferay portlets
问题描述
我需要一些常用于三个不同Liferay portlet的实用程序类,所以我将在一个应该为我的portlet共享的项目中开发它们。
I need some utility classes that will be common for three different Liferay portlets so I will develop them in one project that should be shared for my portlets.
我是使用Eclipse和Liferay IDE插件,我的问题是我需要什么样的项目?
I am using Eclipse with Liferay IDE plugin and my question is what kind of project is that one that I need?
我的意思是它是一个简单的Java项目或任何类型的Liferay项目?
I mean is it a simple Java project or any kind of Liferay project?
推荐答案
有很多方法可以做到这一点:
There are ways you can do this:
- 创建一个简单的Java项目。将其打包为JAR文件。将JAR文件放在全局类路径中如果是tomcat,则全局类路径将是
../ tomcat-7.0.27 / lib / ext /
。 - 创建一个简单的Java项目。将其打包为JAR文件。将JAR文件放在每个portlet的类路径中。
- 使用service-builder创建Liferay插件-portlet,将实用程序类放在
service
包中,以便实用程序类进入[你的项目名称] -service.jar
。然后在需要这些类的portlet中指定属性
required-deployment-contexts = [name-of-your-project]in
每个portlet的liferay-plugin-package.properties`。 - 使用service-builder创建一个Liferay插件-portlet,将实用程序类放在<$ c中$ c> service package,以便实用程序类进入
[name-of-your-project] -service.jar
然后放入全局类路径中的[name-of-your-project] -service.jar
并将其从WEB-INF / lib中删除
您的portlet项目,以便它不会发生冲突。
- Create a simple Java project. Package it as a JAR file. Put the JAR file in global class-path In case of tomcat the global class-path would be
../tomcat-7.0.27/lib/ext/
. - Create a simple Java project. Package it as a JAR file. Put the JAR file in the classpath of each and every portlet.
- Create a Liferay plugin-portlet using service-builder, put the utility classes in the
service
package so that the utility classes go in the[name-of-your-project]-service.jar
. And then in the portletswhich would need these classes specify the property
required-deployment-contexts=[name-of-your-project]in
liferay-plugin-package.properties` of each of the portlet. - Create a Liferay plugin-portlet using service-builder, put the utility classes in the
service
package so that the utility classes go in the[name-of-your-project]-service.jar
and then put the[name-of-your-project]-service.jar
in the global class-path and remove it from theWEB-INF/lib
of your portlet project so that it does not conflict.
结论
- 如果实用程序类中的代码不依赖于Liferay API,则使用 1st-method 。但是,每次实用程序类发生更改时,都需要重新启动服务器。此实用程序类也可以由
Hooks
使用,因为它位于全局类路径中 - 使用第二方法如果实用程序类中的代码不依赖于Liferay API。这不需要重启服务器。但是实用程序类的任何更改都需要您构建&部署使用这个jar的所有插件portlet。
- 第三种方法:这与第二种方法具有相同的限制或功能,只是你可以使用Liferay API&实用程序类中的自定义服务API。
- 第4种方法:这与第1种方法具有相同的限制或功能,只是您可以使用Liferay API&实用程序类中的自定义服务API。
- Use 1st-method if the code in utility classes does not depend in anyway on the Liferay API. But this would require a server restart everytime there is a change in the utility classes. Also the Utility classes could be used by
Hooks
since it is in the global classpath - Use 2nd-method if the code in utility classes does not depend in anyway on the Liferay API. This would not require server restart. But any change in the utility classes would require you to build & deploy all the plugin-portlets which use this jar.
- 3rd-method: This has the same limitations or features as the 2nd-method, just that you can use Liferay API & your custom service API in the utility classes.
- 4th-method: This has the same limitations or features as the 1st-method, just that you can use Liferay API & your custom service API in the utility classes.
Conclusion
所以这里我列出了专业版和专业版。有利于你自己决定。我很想知道在专家的生活中是否有更多的方法(以及更清洁)。
So here I have listed pros & cons for you to decide for yourself. I would love to know if there are more ways (& much cleaner) to do this in liferay from experts.
这篇关于为不同的liferay portlet开发一个通用的jar库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!