How to override a Liferay JAVA class effectively?

Axel LEFEVRE, modified 5 Years ago. New Member Posts: 3 Join Date: 2/14/20 Recent Posts
Hello, I am trying to override the "OpenIdConnectServiceHandlerImpl .java" class in order to make changes.
When deploying my override jar, I have the following error:

2020-02-12 16:50:32.588 INFO  [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:259] Processing auth-sso-0.0.1.jar
2020-02-12 16:50:38.531 ERROR [fileinstall-/opt/liferay/osgi/modules][LogService:93] Error while starting bundle: file:/opt/liferay/osgi/modules/auth-sso-0.0.1.jar
org.osgi.framework.BundleException: Could not resolve module: com.agrial [1161]_  Unresolved requirement: Import-Package: net.jcip.annotations_ [Sanitized]
        at org.eclipse.osgi.container.Module.start(Module.java:444)
        at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1275)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1248)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:520)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316)


So each time a dependency is missing and I face this error, I add the name of the .jar archive in the bnd.bnd file, then I redeploy the module. I no longer have the error, but another one appears ... The same error, but concerning another dependency, and so on ... I am at the 20th archive listed in the file bnd.bnd. And I don't know how many are needed, but it can last a long time if it's a hundred ...

It is really a heavy and long process. Isn't there another way to deal with this error? A simpler and less time consuming way?We are working on version 7.2.1 GA2

Thanks for your help
thumbnail
Olaf Kock, modified 5 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Axel LEFEVRE:

Hello, I am trying to override the "OpenIdConnectServiceHandlerImpl .java" class in order to make changes.
When deploying my override jar, I have the following error:
...
It is really a heavy and long process. Isn't there another way to deal with this error? A simpler and less time consuming way?We are working on version 7.2.1 GA2

Well, you can't deploy new code without either bringing along its dependencies, or deploying them to the system.
HOW you do that depends on the dependencies that you introduce in your module and the final size that you'd like your module to have.
You can have a look at David's blog article on some gradle options. The free OSGi Basics lesson on Liferay University contains a chapter "Bringing along Dependencies" where I'm still fond of the illustrating animation, but wish that the video wasn't edited right with it emoticon
If the dependencies are all OSGi bundles, there's no need to rebuild your plugin. You can just drop them into Liferay's deploy folder until the dependencies are all met, then your plugin will start automagically. And later plugins will be able to use exactly the same libraries, as they're already there.
thumbnail
Dominik Marks, modified 5 Years ago. Regular Member Posts: 149 Join Date: 8/29/12 Recent Posts
Maybe the "better" way would be to check if you really need those imports. If you do not need these directly in your custom classes you may want to try to exclude the imports in the bnd.bnd file.

Speaking of overwriting the OpenIdConnectServiceHandlerImpl class here is what my bnd.bnd file looked like in a similar project:

Import-Package: \
    !com.google.crypto.tink.subtle,\
    !org.bouncycastle.asn1,\
    !org.bouncycastle.asn1.pkcs,\
    !org.bouncycastle.asn1.x509,\
    !org.bouncycastle.cert,\
    !org.bouncycastle.cert.jcajce,\
    !org.bouncycastle.crypto,\
    !org.bouncycastle.crypto.engines,\
    !org.bouncycastle.crypto.modes,\
    !org.bouncycastle.crypto.params,\
    !org.bouncycastle.openssl,\
    !org.bouncycastle.openssl.jcajce,\
    !org.cryptomator.siv,\
    !com.sun.mail.util,\
    *
Maybe it helps.