Issue
- After targeting a more recent version of the product, you may get a 'cannot find symbol' error for an injected
@Referencein yourFooLocalServiceBaseImplclass. Something like this:error: cannot find symbol
protected com.liferay.asset.kernel.service.AssetLinkLocalService - For this example, your entity's
service.xmlwould look like this:<reference entity="AssetLink" package-path="com.liferay.portlet.asset" />
Environment
- Liferay Workspace
Resolution
- This can happen if the referenced entity has been moved to a diferent package (likely from the kernel to an OSGi module).
- You can check if that's your case by searching for the referenced entity in the project code.
- If that is your case, you can follow the following approach:
- Remove that
<reference>from your entity'sservice.xml. - Instead, reference the desired
*LocalServiceclass from yourFooLocalServiceImplusing the@Referenceannotation. - This is what has been done internally in the product. If we use the
AssetLinkmodularization as an example:- It was implemented in LPS-139732.
-
<reference>s were removed by this commit. -
@References were added to*LocalServiceImpclasses in this commit.
- Remove that
- Note that you will get the following error in case you just change the
package-pathfor the new one:Unable to find AssetLink in Foo
Exception in thread "main" com.liferay.portal.tools.service.builder.ServiceBuilderException: Unable to find AssetLink in Foo
at com.liferay.portal.tools.service.builder.ServiceBuilder.getEntity(ServiceBuilder.java:1244)
at com.liferay.portal.tools.service.builder.ServiceBuilder._resolveEntity(ServiceBuilder.java:8000)
at com.liferay.portal.tools.service.builder.ServiceBuilder.<init>(ServiceBuilder.java:805)
at com.liferay.portal.tools.service.builder.ServiceBuilder.main(ServiceBuilder.java:234)
Caused by: java.io.IOException: Unable to open resource com/liferay/asset/link/service.xml in class loader sun.misc.Launcher$AppClassLoader@1b6d3586
at com.liferay.portal.kernel.util.StringUtil.read(StringUtil.java:2286)
at com.liferay.portal.kernel.util.StringUtil.read(StringUtil.java:2254)
at com.liferay.portal.tools.service.builder.ServiceBuilder.getEntity(ServiceBuilder.java:1239)- You can use another approach too, described in this other article.