Message Boards

Spring MVC Portlet using Maven and custom jar, Liferay 7.1.2

Ana Galvão, modified 4 Years ago.

Spring MVC Portlet using Maven and custom jar, Liferay 7.1.2

New Member Post: 1 Join Date: 10/23/19 Recent Posts
Hello all,
I am currently developing a Spring MVC portlet (using Maven) for Liferay 7.1.2, dist-list, that has a series of dependencies, including a custom external client jar, included in the pom as follows:

    <dependency>
            <groupId>eu.europa</groupId>
            <artifactId>star-abm-client</artifactId>
            <version>0.0.7-SNAPSHOT</version>
            <exclusions>
                 <exclusion>
                    <groupId>commons-beanutils</groupId>
                    <artifactId>commons-beanutils</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>commons-beanutils</groupId>
                    <artifactId>
                        commons-beanutils-bean-collections
                    </artifactId>
                </exclusion>
                <exclusion>
                    <groupId>commons-beanutils</groupId>
                    <artifactId>commons-beanutils-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context-support</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-webmvc-portlet</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-web</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-tx</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

However, when I try to use the portlet, one of two things happen:
- The war includes the jar and a NullPointerException is thrown when referencing  the classes present in the jar in runtime;
- The war does not include the jar and the following exception is thrown:
2019-10-23 09:45:00.753 ERROR [pipe-start 2023][DispatcherPortlet:279] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DistributionList': Failed to introspect bean class [eu.europa.portlet.DistributionList] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: ServiceLocator
       at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1123)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481)
       at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
       at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
       at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
       at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
       at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
       at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
       at org.springframework.web.portlet.FrameworkPortlet.createPortletApplicationContext(FrameworkPortlet.java:368)
       at org.springframework.web.portlet.FrameworkPortlet.initPortletApplicationContext(FrameworkPortlet.java:297)
       at org.springframework.web.portlet.FrameworkPortlet.initPortletBean(FrameworkPortlet.java:271)
       at org.springframework.web.portlet.GenericPortletBean.init(GenericPortletBean.java:124)
       at javax.portlet.GenericPortlet.init(GenericPortlet.java:143)
       at com.liferay.portlet.internal.InvokerPortletImpl.init(InvokerPortletImpl.java:253)
       at com.liferay.portal.monitoring.internal.portlet.MonitoringInvokerPortlet.init(MonitoringInvokerPortlet.java:154)
       at com.liferay.portlet.internal.PortletInstanceFactoryImpl.init(PortletInstanceFactoryImpl.java:269)
       at com.liferay.portlet.internal.PortletInstanceFactoryImpl.create(PortletInstanceFactoryImpl.java:170)
       at com.liferay.portal.kernel.portlet.PortletInstanceFactoryUtil.create(PortletInstanceFactoryUtil.java:48)
       at com.liferay.portlet.PortletBagFactory.create(PortletBagFactory.java:210)
       at com.liferay.portlet.PortletBagFactory.create(PortletBagFactory.java:108)
       at com.liferay.portal.service.impl.PortletLocalServiceImpl.initWAR(PortletLocalServiceImpl.java:932)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke(Method.java:498)
       at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:153)
       at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:125)
       at com.sun.proxy.$Proxy85.initWAR(Unknown Source)
       at com.liferay.portal.kernel.service.PortletLocalServiceUtil.initWAR(PortletLocalServiceUtil.java:466)
       at com.liferay.portal.deploy.hot.PortletHotDeployListener.doInvokeDeploy(PortletHotDeployListener.java:228)
       at com.liferay.portal.deploy.hot.PortletHotDeployListener.invokeDeploy(PortletHotDeployListener.java:96)
       at com.liferay.portal.deploy.hot.HotDeployImpl.doFireDeployEvent(HotDeployImpl.java:232)
       at com.liferay.portal.deploy.hot.HotDeployImpl.fireDeployEvent(HotDeployImpl.java:97)
       at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:27)
       at com.liferay.portal.kernel.servlet.PluginContextListener.fireDeployEvent(PluginContextListener.java:189)
       at com.liferay.portal.kernel.servlet.PluginContextListener.doPortalInit(PluginContextListener.java:179)
       at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:44)
       at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:77)
       at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:59)
       at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:54)
       at com.liferay.portal.kernel.servlet.PluginContextListener.contextInitialized(PluginContextListener.java:141)
       at com.liferay.portal.osgi.web.wab.extender.internal.adapter.ServletContextListenerExceptionAdapter._initializeContext(ServletContextListenerExceptionAdapter.java:119)
       at com.liferay.portal.osgi.web.wab.extender.internal.adapter.ServletContextListenerExceptionAdapter.contextInitialized(ServletContextListenerExceptionAdapter.java:99)
       at sun.reflect.GeneratedMethodAccessor431.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke(Method.java:498)
       at org.eclipse.equinox.http.servlet.internal.registration.ListenerRegistration$EventListenerInvocationHandler.invoke(ListenerRegistration.java:143)
       at com.sun.proxy.$Proxy676.contextInitialized(Unknown Source)
       at org.eclipse.equinox.http.servlet.internal.context.ContextController.doAddListenerRegistration(ContextController.java:350)
       at org.eclipse.equinox.http.servlet.internal.context.ContextController.addListenerRegistration(ContextController.java:303)
       at org.eclipse.equinox.http.servlet.internal.customizer.ContextListenerTrackerCustomizer.addingService(ContextListenerTrackerCustomizer.java:67)
       at org.eclipse.equinox.http.servlet.internal.customizer.ContextListenerTrackerCustomizer.addingService(ContextListenerTrackerCustomizer.java:1)
       at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:943)
       at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
       at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
       at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
       at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:903)
       at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
       at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:891)
       at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:804)
       at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
       at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:228)
       at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
       at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:487)
       at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:1004)
       at com.liferay.portal.osgi.web.wab.extender.internal.WabBundleProcessor.initListeners(WabBundleProcessor.java:571)
       at com.liferay.portal.osgi.web.wab.extender.internal.WabBundleProcessor.init(WabBundleProcessor.java:217)
       at com.liferay.portal.osgi.web.wab.extender.internal.WebBundleDeployer._initWabBundle(WebBundleDeployer.java:184)
       at com.liferay.portal.osgi.web.wab.extender.internal.WebBundleDeployer.doStart(WebBundleDeployer.java:106)
       at com.liferay.portal.osgi.web.wab.extender.internal.WabFactory$WABExtension.start(WabFactory.java:175)
       at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)
       at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)
       at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:488)
       at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:1)
       at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)
       at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:450)
       at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:908)
       at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
       at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
       at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:230)
       at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:137)
       at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:129)
       at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:191)
       at org.eclipse.osgi.container.Module.publishEvent(Module.java:476)
       at org.eclipse.osgi.container.Module.start(Module.java:467)
       at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)
       at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:447)
       at org.eclipse.equinox.console.commands.EquinoxCommandProvider.start(EquinoxCommandProvider.java:243)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke(Method.java:498)
       at org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:139)
       at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:91)
       at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:599)
       at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:526)
       at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:415)
       at org.apache.felix.gogo.runtime.Pipe.doCall(Pipe.java:416)
       at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:229)
       at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:59)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
       at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: ServiceLocator
       at java.lang.Class.getDeclaredMethods0(Native Method)
       at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
       at java.lang.Class.getDeclaredMethods(Class.java:1975)
       at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:612)
       at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:523)
       at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:509)
       at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:245)
       ... 107 more
Caused by: java.lang.ClassNotFoundException: ServiceLocator cannot be found by star-abm-dist-list_1.0.0
       at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:508)
       at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:419)
       at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:411)
       at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
       ... 114 more

Either way I am not being able to access the classes present in that jar. Can you help me understand how that correctly manage that dependency in the project?(Using Liferay Developer StudioVersion: 3.7.1.201910160309-ga2)