Liferay hook works with external customized jar which is built by Spring

I ran into the issue when I was customizing organization in Liferay. My organization hook needs to connect with external tables outside Liferay database. Another limitation is I have to use ant to build the project. If I can use maven, I can add all jar dependency in pom.xml. But in ant way, I don't know how to dynamically add jars since my customized jar will be generated into common/lib folder.

In my previous blog, I show ways to do that with maven project. If we have to use ant to do that, other stuff is the same, the only different thing is I have to manually copy all dependent jars into project/WEB-INF/lib folder. Then all things will be done.

Obviously I can't do that, so I combine portlet and hook. In my portlet, I add hook functionality. Just copy liferay-hook.xml in your hook project into your portlet project, then copy your impl class into your project's java code. Then all things are done. This is not a good way, but it's better than directly copy jars into lib.


The link tells something about external jars in a hook.

http://www.liferay.com/community/forums/-/message_boards/message/7454307


It depends on why you need to call your custom classes and if you need access to any additional libraries as well (particularly if those additional libraries cannot be placed in the global class loader due to conflicts):

Manually put it in the global class loader locations. You're already doing this. As long as you never need any other Liferay classes that are inaccessible outside of the global class loader, this is the recommended route.
If you want to go down the tried-and-proven route, switch to using an EXT plugin which will achieve the same thing. It will copy all the files in ext-web to the Liferay folder and give those JSPs access to classes in the ext-impl and ext-service folders. This gives you access to libraries in the Liferay class loader.
Turn your hook into a portlet (which is allowed to have a liferay-hook.xml) and have your hook JSP generate portlet URLs to your portlet for all the actual work. This is a more difficult route to implement, but it gives you class loader separation which is preferred by some people since this means you can constantly redeploy without restarting the server.
If for some reason you want to leave everything as a hook rather than convert to an EXT plugin, then if you're comfortable figuring out your own build process for that custom code, put the JAR file in the WEB-INF/lib folder of your custom-jsps folder (this does not usually exist, you would have to create it). You still need to restart the server and you have to write your own build scripts, so no real benefit over an EXT plugin.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值