Forums de discussion

Liferay 7, osgi module for mvc portlet doesnt find dependencies

thumbnail
Daniele Baggio, modifié il y a 7 années.

Liferay 7, osgi module for mvc portlet doesnt find dependencies

Expert Publications: 336 Date d'inscription: 05/12/08 Publications récentes
Hi,

I've start the new module using
blade create -t portlet -p com.liferay.docs.portlet -c MyPortlet my-portlet-project


This is my gradle.build

dependencies {
	compile group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
	compile group: "javax.portlet", name: "portlet-api", version: "2.0"
	compile group: "javax.servlet", name: "servlet-api", version: "2.5"
	compile group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"

	compile group: "com.liferay", name: "com.liferay.my.account.web", version: "1.0.2"
	compile group: "com.liferay", name: "com.liferay.users.admin.web", version: "1.0.4"
}


In the portal the module com.liferay.my.account.web is at 1.0.2 version, but in the repository https://repository.liferay.com/nexus/content/repositories/liferay-ce/com/liferay/com.liferay.my.account.web/ the version is still 1.0.1

Building the module I have this error:


λ gradle build
:modules:my-mvc-portlet-project:compileJava

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration ':modules:my-mvc-portlet-project:compile'.
> Could not find com.liferay:com.liferay.my.account.web:1.0.2.
  Searched in the following locations:
      http://cdn.repository.liferay.com/nexus/content/groups/public/com/liferay/com.liferay.my.account.web/1.0.2/com.liferay.my.account.web-1.0.2.pom
      http://cdn.repository.liferay.com/nexus/content/groups/public/com/liferay/com.liferay.my.account.web/1.0.2/com.liferay.my.account.web-1.0.2.jar
  Required by:
      plugins-sdk-7.0.modules:my-mvc-portlet-project:1.0.0



Setting versione 1.0.1 for com.liferay.my.account.web the gradle build is ok, but the deploy process fails with:

λ blade deploy
stop 503
update 503 file:/C:/java/projects/LF7x/workspace/plugins-sdk-7.0/modules/my-mvc-portlet-project/build/libs/my.mvc.portlet.project-1.0.0.jar
Updated bundle 503
start 503
org.osgi.framework.BundleException: Could not resolve module: my.mvc.portlet.project [503]
  Unresolved requirement: Import-Package: com.liferay.my.account.web.portlet.action


Help me please..
thumbnail
Daniele Baggio, modifié il y a 7 années.

RE: Liferay 7, osgi module for mvc portlet doesnt find dependencies

Expert Publications: 336 Date d'inscription: 05/12/08 Publications récentes
For the complete source look at:

https://github.com/baxtheman/liferay7GA1-sandbox/tree/master/modules
thumbnail
Daniele Baggio, modifié il y a 7 années.

RE: Liferay 7, osgi module for mvc portlet doesnt find dependencies

Expert Publications: 336 Date d'inscription: 05/12/08 Publications récentes
To continue the story...

I fix the bnd.bnd with an explicit import package directive:


Bundle-SymbolicName: my.mvc.portlet.project
Bundle-Version: 1.0.0
Import-Package:\
	!com.liferay.my.account.web.*


The deploy runs without problem, It's seems resolved but portal has a runtime error:


08:51:02,230 ERROR [Thread-120][my_mvc_portlet_project:97] BundleComponentActivator : Bundle [503] Unexpected failure enabling component holder com.liferay.docs.mvcportlet.action.EditUserMVCActionCommand
java.lang.NoClassDefFoundError: com/liferay/my/account/web/portlet/action/EditUserMVCActionCommand
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
        at org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:272)
        at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)


But meanwhile I discover the core module com.liferay.my.account.web has some private packages:


g! headers 436

Liferay My Account Web (436)
----------------------------
Manifest-Version = 1.0
Bnd-LastModified = 1458582143550
Bundle-ManifestVersion = 2
Bundle-Name = Liferay My Account Web
Bundle-SymbolicName = com.liferay.my.account.web
...
...
Private-Package = com.liferay.my.account.web.application.list,com.liferay.my.account.web.constants,com.liferay.my.account.web.portlet,com.liferay.my.account.web.portlet.action,com.liferay.my.account.web.upgrade,content,resource-actions


This means the bundle I've build and deploy cannot resolve the package com.liferay.my.account.web.portlet.action ....

Is it impossible to solve this situation?
Neil Bartlett, modifié il y a 7 années.

RE: Liferay 7, osgi module for mvc portlet doesnt find dependencies

New Member Envoyer: 1 Date d'inscription: 28/04/16 Publications récentes
Your Import-Package statement is bad. This statement in a bnd file is a list of patterns that are matched against the dependencies discovered from the class file. So if you say this:

Import-Package: !org.foo.*


then it means "don't import packages matching org.foo.*... and don't import anything else either"!! You need to fix this by adding a trailing catch-all wild card:

Import-Package: !org.foo.*, *


which means "don't import packages matching org.foo.*, but import everything else my code depends on".
thumbnail
Daniele Baggio, modifié il y a 7 années.

RE: Liferay 7, osgi module for mvc portlet doesnt find dependencies

Expert Publications: 336 Date d'inscription: 05/12/08 Publications récentes
Yes, you are right, the Import-Package is bad written.

Fixed the bnd.bnd, but the problem still remains and my module is unable to consume the com/liferay/my/account/web/portlet/action package.
thumbnail
Daniele Baggio, modifié il y a 7 années.

[resolved] Liferay 7, osgi module for mvc portlet doesnt find dependencies

Expert Publications: 336 Date d'inscription: 05/12/08 Publications récentes
I finally solved this issue with a workaround and changing the some develpment choices.

I removed any
com.liferay.my.account.web
dependencies and I copied the original code from the core to my module.
I've copied the entire
com.liferay.my.account.web.portlet.action.EditUserMVCActionCommand
class body into my new custom ActionCommand.

My test module now is based on com.liferay.users.admin.web package only:


dependencies {
	compile group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
	compile group: "javax.portlet", name: "portlet-api", version: "2.0"
	compile group: "javax.servlet", name: "servlet-api", version: "2.5"
	compile group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"

	compile group: "com.liferay", name: "com.liferay.users.admin.web", version: "1.0.4"
}


The complete code is here https://github.com/baxtheman/liferay7GA1-sandbox/tree/master/modules

To me this is not the best way to have a "my account" clone module, maybe this is a better way..
thumbnail
Ray Augé, modifié il y a 7 années.

RE: Liferay 7, osgi module for mvc portlet doesnt find dependencies

Liferay Legend Publications: 1197 Date d'inscription: 08/02/05 Publications récentes
Just one point! Is the package com.liferay.my.account.web.portlet.action exported from the my.acount module? If not, you won't be able to import it.
thumbnail
Daniele Baggio, modifié il y a 7 années.

RE: Liferay 7, osgi module for mvc portlet doesnt find dependencies

Expert Publications: 336 Date d'inscription: 05/12/08 Publications récentes
Exactly Ray,
the com.liferay.my.account.web.portlet.action is in Private-packages!
It's not easy to understand what is public or private during development.. ./gradle build compiles anyway.
sandip patel, modifié il y a 7 années.

RE: Liferay 7, osgi module for mvc portlet doesnt find dependencies

New Member Publications: 2 Date d'inscription: 22/02/14 Publications récentes
Hi,

I am trying to add spring dependency but its not loading .
thumbnail
Ray Augé, modifié il y a 7 années.

RE: Liferay 7, osgi module for mvc portlet doesnt find dependencies

Liferay Legend Publications: 1197 Date d'inscription: 08/02/05 Publications récentes
Can you give more information?
thumbnail
Ray Augé, modifié il y a 7 années.

RE: Liferay 7, osgi module for mvc portlet doesnt find dependencies

Liferay Legend Publications: 1197 Date d'inscription: 08/02/05 Publications récentes
you could add

-check: all 


to you bnd.bnd file and bnd will complain when you try to import a package which is not exported.