掲示板

Liferay 7 - Missing JAR in Tomcat for Auto Login

thumbnail
6年前 に Mohammed Rawoof Shaik によって更新されました。

Liferay 7 - Missing JAR in Tomcat for Auto Login

Junior Member 投稿: 37 参加年月日: 16/09/25 最新の投稿
Hello LR Community,

Requirement:
Setup auto login by following the steps in this article. I've created a new hook plugin and have a class implementing 'com.liferay.portal.kernel.security.auto.login.AutoLogin', as stated in the article. And I have added the required dependency in the pom.xml,
		<dependency>
			<groupid>com.liferay.portal</groupid>
			<artifactid>portal-service</artifactid>
			<version>7.0.0-nightly</version>
			<scope>provided</scope>
		</dependency>


Issue:
When I deployed the war file, I got the below exception,
Caused by: java.lang.NoClassDefFoundError: com/liferay/portal/NoSuchUserException
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
        at java.lang.Class.getConstructor0(Class.java:3075)
        at java.lang.Class.newInstance(Class.java:412)
        at com.liferay.portal.kernel.util.InstanceFactory.newInstance(InstanceFactory.java:67)
        at com.liferay.portal.kernel.util.InstanceFactory.newInstance(InstanceFactory.java:27)
        at com.liferay.portal.kernel.util.ProxyFactory.newInstance(ProxyFactory.java:54)
        at com.liferay.portal.kernel.util.ProxyFactory.newInstance(ProxyFactory.java:45)
        at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.newInstance(BaseHotDeployListener.java:81)
        at com.liferay.portal.deploy.hot.HookHotDeployListener.initAutoLogins(HookHotDeployListener.java:777)
        at com.liferay.portal.deploy.hot.HookHotDeployListener.initPortalProperties(HookHotDeployListener.java:1325)
        at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:467)
        at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:271)
        ... 62 more
Caused by: java.lang.ClassNotFoundException: com.liferay.portal.NoSuchUserException cannot be found by grouper-ldap-login-hook-1.0.0-SNAPSHOT_1.0.0.SNAPSHOT
        at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:394)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:357)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:349)
        at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 75 more


Proposed Solution:
I searched for 'com.liferay.portal.NoSuchUserException' in grepcode, which suggested it is in the 'portal-service.jar'. I compared 'liferay-portal-6.2-ce-ga6/tomcat-7.0.62/lib/ext' with 'liferay-ce-portal-7.0-ga4/tomcat-8.0.32/lib/ext' and found this JAR isn't present in LR7 tomcat directory. I added the 'portal-service.jar' from 'liferay-portal-6.2-ce-ga6/tomcat-7.0.62/lib/ext' to 'liferay-ce-portal-7.0-ga4/tomcat-8.0.32/lib/ext' and restarted the server which gave the below logs,
15:46:54,109 INFO  [fileinstall-/portal/liferay-ce-portal-7.0-ga4-upgrade/osgi/war][HotDeployImpl:226] Deploying grouper-ldap-login-hook-1.0.0-SNAPSHOT from queue
15:46:54,110 INFO  [fileinstall-/portal/liferay-ce-portal-7.0-ga4-upgrade/osgi/war][PluginPackageUtil:1007] Reading plugin package for grouper-ldap-login-hook-1.0.0-SNAPSHOT
25-Aug-2017 15:46:54.112 INFO [fileinstall-/portal/liferay-ce-portal-7.0-ga4-upgrade/osgi/war] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
15:46:54,133 INFO  [fileinstall-/portal/liferay-ce-portal-7.0-ga4-upgrade/osgi/war][HookHotDeployListener:456] Registering hook for grouper-ldap-login-hook-1.0.0-SNAPSHOT
15:46:54,168 INFO  [fileinstall-/portal/liferay-ce-portal-7.0-ga4-upgrade/osgi/war][HookHotDeployListener:532] Hook for grouper-ldap-login-hook-1.0.0-SNAPSHOT is available for use
15:46:54,304 INFO  [fileinstall-/portal/liferay-ce-portal-7.0-ga4-upgrade/osgi/war][BundleStartStopLogger:35] STARTED grouper-ldap-login-hook-1.0.0-SNAPSHOT_1.0.0.SNAPSHOT [525]


Question:
Since 'portal-service.jar' isn't present in LR7 server lib directory, I'm assuming it's intentionally removed my the developers. And I've added this JAR from the 'liferay-portal-6.2-ce-ga6' package to resolve the dependency errors I'm getting,
  • Would this cause any issues?
  • Is this a known issue?, as I didn't find anything in Liferay's JIRA
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: Liferay 7 - Missing JAR in Tomcat for Auto Login

Liferay Legend 投稿: 6400 参加年月日: 08/09/23 最新の投稿
Mohammed Rawoof Shaik:
Question:
Since 'portal-service.jar' isn't present in LR7 server lib directory, I'm assuming it's intentionally removed my the developers. And I've added this JAR from the 'liferay-portal-6.2-ce-ga6' package to resolve the dependency errors I'm getting,
  • Would this cause any issues?
  • Is this a known issue?, as I didn't find anything in Liferay's JIRA


This is a particularly bad idea. Yes, you'll run into problems. Just because you found it in 6.2's portal-service does not mean that it's not there any more. It's here, and actually in portal-kernel. Just declare a dependency to portal-kernel, as you can see in this sample project and you're done. Well - you're done as soon as you have removed that old code from your classpath.
thumbnail
6年前 に Mohammed Rawoof Shaik によって更新されました。

RE: Liferay 7 - Missing JAR in Tomcat for Auto Login

Junior Member 投稿: 37 参加年月日: 16/09/25 最新の投稿
Hi Olaf,

Thanks for the insight. I reverted everything to the initial state, i.e., removed 'liferay-ce-portal-7.0-ga4/tomcat-8.0.32/lib/ext/portal-service.jar' I copied from liferay-portal-6.2-ce-ga6. The issue was the <scope>provided</scope> attribute in the pom.xml. I removed this attribute and updated the dependencies in the pom as below,

<dependencies>

		<!-- Liferay SDK -->
		<dependency>
			<groupid>com.liferay.portal</groupid>
			<artifactid>portal-service</artifactid>
			<version>${liferay.version}</version>
		</dependency>
		<dependency>
			<groupid>com.liferay.portal</groupid>
			<artifactid>com.liferay.portal.impl</artifactid>
			<version>2.20.0</version>
		</dependency>
		<dependency>
			<groupid>com.liferay.portal</groupid>
			<artifactid>com.liferay.portal.kernel</artifactid>
			<version>2.42.0</version>
		</dependency>

		<!-- OSGI -->
		<dependency>
			<groupid>org.osgi</groupid>
			<artifactid>org.osgi.service.component.annotations</artifactid>
			<version>1.3.0</version>
			<scope>provided</scope>
		</dependency>

		<!-- Servlet -->
		<dependency>
			<groupid>javax.servlet</groupid>
			<artifactid>servlet-api</artifactid>
			<version>2.4</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupid>javax.portlet</groupid>
			<artifactid>portlet-api</artifactid>
			<version>2.0</version>
			<scope>provided</scope>
		</dependency>

	</dependencies>


But now when I deploy the WAR package I get the below error,

15:19:10,782 INFO  [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:252] Processing shibboleth-autologin-hook-snapshot.war
15:19:21,102 INFO  [fileinstall-/portal/liferay-ce-portal-7.0-ga4-upgrade/osgi/war][BaseAutoDeployListener:43] Copying portlets for /portal/liferay-ce-portal-7.0-ga4-upgrade/tomcat-8.0.32/temp/20170831151921019UYSYZDSA/shibboleth-autologin-hook-snapshot.war
15:19:21,104 INFO  [fileinstall-/portal/liferay-ce-portal-7.0-ga4-upgrade/osgi/war][PortletAutoDeployListener:47] Deploying package as a web application
15:19:21,193 INFO  [fileinstall-/portal/liferay-ce-portal-7.0-ga4-upgrade/osgi/war][BaseDeployer:879] Deploying shibboleth-autologin-hook-snapshot.war
15:19:22,207 ERROR [fileinstall-/portal/liferay-ce-portal-7.0-ga4-upgrade/osgi/war][org_apache_felix_fileinstall:97] Failed to install artifact: /portal/liferay-ce-portal-7.0-ga4-upgrade/osgi/war/shibboleth-autologin-hook-snapshot.war
java.lang.RuntimeException: com.liferay.portal.kernel.deploy.auto.AutoDeployException: java.lang.NullPointerException
        at com.liferay.portal.osgi.web.wab.generator.internal.processor.WabProcessor.executeAutoDeployers(WabProcessor.java:254)
        at com.liferay.portal.osgi.web.wab.generator.internal.processor.WabProcessor.autoDeploy(WabProcessor.java:157)
        at com.liferay.portal.osgi.web.wab.generator.internal.processor.WabProcessor.getProcessedFile(WabProcessor.java:108)
        at com.liferay.portal.osgi.web.wab.generator.internal.WabGenerator.generate(WabGenerator.java:86)
        at com.liferay.portal.osgi.web.wab.generator.internal.connection.WabURLConnection.getInputStream(WabURLConnection.java:77)
        at java.net.URL.openStream(URL.java:1045)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.install(DirectoryWatcher.java:949)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.install(DirectoryWatcher.java:871)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:485)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:361)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:312)
Caused by: com.liferay.portal.kernel.deploy.auto.AutoDeployException: java.lang.NullPointerException
        at com.liferay.portal.tools.deploy.BaseDeployer.autoDeploy(BaseDeployer.java:226)
        at com.liferay.portal.deploy.auto.ThreadSafeAutoDeployer.autoDeploy(ThreadSafeAutoDeployer.java:39)
        at com.liferay.portal.kernel.deploy.auto.BaseAutoDeployListener.deploy(BaseAutoDeployListener.java:47)
        at com.liferay.portal.osgi.web.wab.generator.internal.processor.WabProcessor.executeAutoDeployers(WabProcessor.java:251)
        ... 10 more
Caused by: java.lang.NullPointerException
        at com.liferay.portal.deploy.auto.WAIAutoDeployer.copyXmls(WAIAutoDeployer.java:76)
        at com.liferay.portal.tools.deploy.BaseDeployer.deployDirectory(BaseDeployer.java:670)
        at com.liferay.portal.tools.deploy.BaseDeployer.deployFile(BaseDeployer.java:1084)
        at com.liferay.portal.tools.deploy.BaseDeployer.deployFile(BaseDeployer.java:1015)
        at com.liferay.portal.tools.deploy.BaseDeployer.autoDeploy(BaseDeployer.java:223)
        ... 13 more


The error is ambiguous, and I'm unable to find a root cause for this error.
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: Liferay 7 - Missing JAR in Tomcat for Auto Login (回答)

Liferay Legend 投稿: 6400 参加年月日: 08/09/23 最新の投稿
As there's no portal-service for Liferay 7 (independent of what your ${liferay.version} is declared as): Remove that dependency.

portal-kernel is provided (no need to bundle it in your WAR file, it's in tomcat/lib/ext.)

And I'm not sure what your impl dependency in there does. Packages with "impl" in them should never be depended on.
thumbnail
6年前 に Mohammed Rawoof Shaik によって更新されました。

RE: Liferay 7 - Missing JAR in Tomcat for Auto Login

Junior Member 投稿: 37 参加年月日: 16/09/25 最新の投稿
Hi Olaf,

Thanks. I did as you mentioned and the deployment was successful.