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.

發佈了107 篇原創文章 · 獲贊 11 · 訪問量 33萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章