Problem resolving dependency for DXP module

thumbnail
Jorge Rivera, modified 6 Years ago. Junior Member Posts: 26 Join Date: 11/16/11 Recent Posts

Hello

 

I've been trying to build a google api plugin, it works flawlessly in 6.2 but when I try to include de same jar file that works in 6.2 as a module in DXP the module does not resolve and keeps asking me for more dependencies but there's one I can't meet yet, this is the error I get:

 

19:35:55,248 ERROR [Framework Event Dispatcher: Equinox Container: 900c2611-2111-0019-17e8-93f5b53ee20e][com_qad_utils_google:97] FrameworkEvent ERROR 
org.osgi.framework.BundleException: Could not resolve module: com.qad.utils.google [1969]_  Unresolved requirement: Import-Package: afu.com.sun.org.apache.xerces.internal.parsers_ [Sanitized]
    at org.eclipse.osgi.container.Module.start(Module.java:429)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1562)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1476)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

Where do I get that weird package afu.com.sun.org.apache.xerces.internal.parsers, I've found com.sun.org.apache.xerces.internal.parsers but the plugin does not pick it up that, if I remove the dependency that injects it I see a different afu package and only org.checkerframework:checker-qual:2.0.0 meets that weird afu structure, I'm using the latest versions of the dependencies.

 

These are my libraries and dependencies:

Libraries added to 6.2 jar via pom.xml

com.google.api-client:google-api-client:1.27.0, exclude guava
com.google.guava:guava:20.0
com.google.http-client:google-http-client:1.27.0
com.google.api-client:google-api-client-java6:1.27.0
com.google.http-client:google-http-client-jackson2:1.27.0
com.google.http-client:google-http-client-gson:1.27.0
com.google.oauth-client:google-oauth-client:1.27.0
com.google.oauth-client:google-oauth-client-java6:1.27.0
org.glassfish:avax.jms:3.2-b06
com.google.apis:google-api-services-drive:v3-rev136-1.25.0
com.google.apis:google-api-services-slides:v1-rev294-1.23.0
com.google.errorprone:error_prone_annotations:2.3.2
org.apache.logging.log4j.osgi:log4j-osgi:2.0-rc1

 

Dependencies:

    compileInclude group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.9'
    compileInclude group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.7.9'
    compileInclude group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.7.9'
    compileInclude group: 'org.checkerframework', name: 'checker', version: '2.0.0'
    compileInclude group: 'org.checkerframework', name: 'checker-qual', version: '2.0.0'

 

This is my bnd file:

Bundle-Name: qad-utils-google
Bundle-SymbolicName: com.qad.utils.google
Bundle-Version: 1.0.0
Export-Package: qad.utils.google
Include-Resource: @SlidesAPI-2.0.jar

 

I hope someone can help.

 

Regards

 

 

thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts

Hi Jorge,

 

Have you tried anything from, possible, one of the most read Liferay blog posts of all time that David wrote?

 

https://community.liferay.com/blogs/-/blogs/osgi-module-dependencies

 

If yes, can you share with us which items you tried?

thumbnail
Jorge Rivera, modified 6 Years ago. Junior Member Posts: 26 Join Date: 11/16/11 Recent Posts
Andrew Jardine:

Hi Jorge,

 

Have you tried anything from, possible, one of the most read Liferay blog posts of all time that David wrote?

 

https://community.liferay.com/blogs/-/blogs/osgi-module-dependencies

 

If yes, can you share with us which items you tried?

Hello Andrew

 

I tried them all, the one that closely worked was option 4 but it gave me the same issue. I ended up using compileInclude in the gradle file and it was it, I've looked for the afu.com package withing the included jars and it is not there, that is why I keep looking for some jar file that contains the package the closest I've found is:

compile group: 'xerces', name: 'xercesImpl', version: '2.6.2-jaxb-1.0.6'

It contains com.sun.org.apache.xerces.internal.parsers but not the one starting with afu that I'm being asked by the dependencies I already have.

 

Hope it makes sense.

 

Regards

thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts

Hi Jorge,

 

I love OSGI, except for when it comes to these dependency management things -- in those moments, OSGI and I tend to have a rocky relationship :).

 

Most of the time when I am fighting with these scenarios, it stems from a dependency that I have added to my project that ALSO has a dependency that I don't have. So while I meet the needs of Gradle to let me code and build, the runtime is another story -- which sounds to me like what you are stuggling with. Dependency trees can often take longer to resolve than the time it takes to build your actual plugin. 

Question, you mentioned in 6.2, in your maven project, that the following jars are referenced --

Libraries added to 6.2 jar via pom.xml

com.google.api-client:google-api-client:1.27.0, exclude guava
com.google.guava:guava:20.0
com.google.http-client:google-http-client:1.27.0
com.google.api-client:google-api-client-java6:1.27.0
com.google.http-client:google-http-client-jackson2:1.27.0
com.google.http-client:google-http-client-gson:1.27.0
com.google.oauth-client:google-oauth-client:1.27.0
com.google.oauth-client:google-oauth-client-java6:1.27.0
org.glassfish:avax.jms:3.2-b06
com.google.apis:google-api-services-drive:v3-rev136-1.25.0
com.google.apis:google-api-services-slides:v1-rev294-1.23.0
com.google.errorprone:error_prone_annotations:2.3.2
org.apache.logging.log4j.osgi:log4j-osgi:2.0-rc1

 

Are they defined in the pom as provided? Have you tried simply taking the jars from that plugin and shoving them into your gradle plugin, bundling the jars with your module? Honestly, I wouln't go with that as a FINAL solution since you could easily debate whether or not that is a proper solution, but you could start there to make sure that you have all the libs you needed and then from there convert those libs that are not OSGI aware, to OSGI aware so that you could deploy them directly to the container without needing to bundle them with your plugin.

... Or have I totally misunderstood your question/problem? :)

 

 

thumbnail
Jorge Rivera, modified 6 Years ago. Junior Member Posts: 26 Join Date: 11/16/11 Recent Posts

Hi Andrew

It something like that, I've been building a Frankenstein here, I jave a fully tested java library created for our 6.2 portal, it is not a Liferay plugin, such jar file includes all dependencies in the jar, exploding the jar file has all the paths for the libraries in the pom file.

I figured that I could just add the library to a plugin like we did before in 6.2, by copying it to the lib folder inside the plugin but it turns out that it requires more dependencies that were not needed in 6.2. I guess I am wrong on this regard.

You mention dependency tree resolving, I tried creating a module that replaced the library but the outcome is the same, the afu xerces dependency is not met by any library I've tried in mvnrepository.

How can I convert my library into a OSGI aware library? Is there any documentation that guide me in the right direction? I've looked but I haven't had any luck finding something that works. I followed this post in stackoverflow but it did not work, it keeps asking for that weird dependency, I used the google api version 1.20, walked my way up to the latest that is 1.27, still no luck.

Regards

thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts

Hi Jorge, 

I have been lucky as of late and haven't had to worry much about these problems. The few times, recently, where I almost had to worry about them (like with the Joda time libraries) I was lucky enough to find artifacts that were already converted for me. I looked back through my history in my browser though to see if I could dig up what I THINK was the link I followed to do this, but again, it has been a while so I don't know if this is the right link.

 

https://www.ibm.com/support/knowledgecenter/en/SSEQTP_9.0.0/com.ibm.websphere.osgi.doc/ae/ra_convert_jar_to_bundle.html

or it might have been this one (I believe Adobe EM using the Felix container as well)

https://helpx.adobe.com/ca/experience-manager/kb/ConvertAJarIntoOsgiBundle.html

or possbily this one? but less likely as I use Intellij, not eclipse 

https://stackoverflow.com/questions/9819090/how-to-convert-jar-to-osgi-bundle-using-eclipse-and-bndtools

 

The gist of it is that you need to provide the manifest file that describes the bundle and the most important, especially in your case, is to make sure that you define the right imports (based on the bundle needs) and the right exports (based on other bundles needs). Make no mistake about it, this can be a tedious, time consuming and almost painful exercise. With that said, if you are doing it for publicly shared jars, others would likely appreciate you sharing them with others either via PR, or by submitting them to the maven repo. 

 

.. if either or those links end up working for yo though, could you let me know so that I can mark it as a possible solution in case I run into this same issue again in the future? :)