Could not initialize class com.liferay.portal.model.impl.GroupImpl

954 Views Asked by At

I am migrating liferay 6 to 7.4. Test case was previously written in 6 and now going to update the liferay dependency so after upgrade lib, I am facing issue that class clould not initialize . I have added all the required lib that are used in liferay 7.4 Following is my pom file.

<?xml version="1.0" encoding="UTF-8"?>

4.0.0

<parent>
    <groupId>com.baxter.home</groupId>
    <artifactId>NH-Common-Home-Platform</artifactId>
    <version>21.0.1-SNAPSHOT</version>
</parent>

<artifactId>NH-Core-Liferay</artifactId>
<name>${project.artifactId}</name>
<version>21.0.1-SNAPSHOT</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.scm.baseUrl>https://usrl2subapp014.global.baxter.com/svn/NewHzn_Application/Platform</project.scm.baseUrl>
    <project.scm.branch>branches/Platform-10.2.0-R3-SPO</project.scm.branch>
</properties>

<scm>
    <connection>scm:svn:${project.scm.baseUrl}/${project.scm.branch}/${project.artifactId}</connection>
    <developerConnection>scm:svn:${project.scm.baseUrl}/${project.scm.branch}/${project.artifactId}</developerConnection>
    <url>${project.scm.baseUrl}/${project.scm.branch}/${project.artifactId}</url>
</scm>

<dependencies>
    <!-- At Home Platform -->
    <dependency>
        <groupId>com.baxter.home</groupId>
        <artifactId>NH-Core-Renal</artifactId>
        <version>21.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.baxter.renal</groupId>
        <artifactId>NH-TechArch</artifactId>
        <version>21.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.baxter.home</groupId>
        <artifactId>NH-Core</artifactId>
        <version>21.0.1-SNAPSHOT</version>
    </dependency>

    <!-- Liferay -->
    <dependency>
        <groupId>com.liferay.portal</groupId>
        <artifactId>release.dxp.api</artifactId>
        <version>7.4.13.u3</version>
        <scope>provided</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.liferay.portal/com.liferay.portal.impl -->
    <dependency>
        <groupId>com.liferay.portal</groupId>
        <artifactId>com.liferay.portal.impl</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-hibernate3 -->
    <!-- <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-hibernate3</artifactId>
        <version>2.0.8</version>
    </dependency> -->

    <!-- JSR Standards -->

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.portlet</groupId>
        <artifactId>portlet-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Utilities -->

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>

    <!-- findbugs annotations -->
    <dependency>
        <groupId>findbugs</groupId>
        <artifactId>annotations</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>jsr305</artifactId>
    </dependency>

    <!-- Unit Test -->
    <!-- to avoid ClassFormatError in PlatformPortalUtilStaticTest -->
    <dependency>
        <groupId>org.javassist</groupId>
        <artifactId>javassist</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jodd</groupId>
        <artifactId>jodd</artifactId>
        <version>3.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jodd</groupId>
        <artifactId>jodd-wot</artifactId>
        <version>3.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.baxter.home</groupId>
        <artifactId>NH-Core-Renal</artifactId>
        <type>test-jar</type>
        <scope>test</scope>
        <version>21.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.baxter.home</groupId>
        <artifactId>NH-TestSupport</artifactId>
        <version>1.2.2-SNAPSHOT</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jdbc</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>c3p0</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.1.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>rome</groupId>
        <artifactId>rome</artifactId>
        <version>1.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache-core</artifactId>
        <version>2.4.6</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.freemarker</groupId>
        <artifactId>freemarker</artifactId>
        <version>2.3.17</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>velocity</groupId>
        <artifactId>velocity</artifactId>
        <version>1.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-core</artifactId>
        <version>3.0.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-analyzers</artifactId>
        <version>3.0.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-highlighter</artifactId>
        <version>3.0.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-memory</artifactId>
        <version>3.0.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jruby</groupId>
        <artifactId>jruby</artifactId>
        <version>1.6.4</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.tika/tika-parsers -->
    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-parsers</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika</artifactId>
        <version>0.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.incava</groupId>
        <artifactId>java-diff</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.python</groupId>
        <artifactId>jython</artifactId>
        <version>2.5.0</version>
        <scope>test</scope>
    </dependency>
    <!-- <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> 
        <version>3.0.9</version> <type>pom</type> </dependency> -->
    <!-- <dependency> <groupId>org.edorasframework.liferay.dependencies</groupId> 
        <artifactId>liferay-rhino</artifactId> <version>6.1.10-ee-ga1</version> <scope>test</scope> 
        </dependency> -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.media</groupId>
        <artifactId>jai_core</artifactId>
        <version>1.1.3</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.media/jai_codec -->
    <dependency>
        <groupId>javax.media</groupId>
        <artifactId>jai_codec</artifactId>
        <version>1.1.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.browseengine.bobo</groupId>
        <artifactId>bobo-browse</artifactId>
        <version>3.0.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.ccpp</groupId>
        <artifactId>ccpp</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ical4j</groupId>
        <artifactId>ical4j</artifactId>
        <version>0.9.20</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.im4java</groupId>
        <artifactId>im4java</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>jgroups</groupId>
        <artifactId>jgroups</artifactId>
        <version>2.8.0.GA</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.jackrabbit</groupId>
        <artifactId>jackrabbit-core</artifactId>
        <version>2.1.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.jackrabbit</groupId>
        <artifactId>jackrabbit-api</artifactId>
        <version>2.1.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.jackrabbit</groupId>
        <artifactId>jackrabbit-jcr-commons</artifactId>
        <version>2.1.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.jackrabbit</groupId>
        <artifactId>jackrabbit-spi</artifactId>
        <version>2.1.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.jackrabbit</groupId>
        <artifactId>jackrabbit-spi-commons</artifactId>
        <version>2.1.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.jcr</groupId>
        <artifactId>jcr</artifactId>
        <version>2.0</version>
        <scope>test</scope>
    </dependency>


    <dependency>
        <groupId>net.sf.flexjson</groupId>
        <artifactId>flexjson</artifactId>
        <version>2.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jabsorb</groupId>
        <artifactId>jabsorb</artifactId>
        <version>1.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.outerj.daisy</groupId>
        <artifactId>daisydiff</artifactId>
        <version>1.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.easymock</groupId>
        <artifactId>easymock</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4-rule</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-classloading-xstream</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-easymock</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-mockito</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.oracle.database.jdbc</groupId>
        <artifactId>ojdbc10</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
    </dependency>
    <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>easyconf</groupId>
        <artifactId>easyconf</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>xdoclet</groupId>
                <artifactId>xdoclet</artifactId>
            </exclusion>
            <exclusion>
                <groupId>xdoclet</groupId>
                <artifactId>xdoclet-web-module</artifactId>
            </exclusion>
            <exclusion>
                <groupId>xpp3</groupId>
                <artifactId>xpp3_min</artifactId>
            </exclusion>
            <exclusion>
                <groupId>xstream</groupId>
                <artifactId>xstream</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <finalName>NH-Core-Liferay</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>-Xss512m -Xmx1024m -XX:MaxPermSize=256m</argLine>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <configuration>
                <tagBase>${project.scm.baseUrl}/tags/${project.artifactId}</tagBase>
                <tagNameFormat>@{project.artifactId}-@{project.version}</tagNameFormat>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.atlassian.maven.plugins</groupId>
            <artifactId>maven-clover2-plugin</artifactId>
            <version>3.1.2</version>
            <configuration>
                <includes>
                    <include>**/*.java</include>
                </includes>
                <excludes>
                    <exclude>**/liferay/domain/BasicSite.java</exclude>
                    <exclude>**/liferay/domain/BasicSiteUser.java</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

Following is my error log trace

java.lang.NoClassDefFoundError: Could not initialize class com.liferay.portal.model.impl.GroupImpl
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at javassist.runtime.Desc.getClassObject(Desc.java:72)
at javassist.runtime.Desc.getClassType(Desc.java:181)
at javassist.runtime.Desc.getType(Desc.java:151)
at javassist.runtime.Desc.getType(Desc.java:107)
at com.baxter.home.core.liferay.service.impl.LiferaySiteServiceImplTest.setup(LiferaySiteServiceImplTest.java:107)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:133)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:96)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:127)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

Can anyone help me to figure out this issue. Thanks for your support

1

There are 1 best solutions below

1
Olaf Kock On

That is an impressive list of dependencies, and apparently quite a big plugin.

Let's start with this: My recommendation is to simplify this list. There are several dependencies in there, that used to be used in Liferay 6.x, but are no longer there/supported in 7.4 - for example lucene, jackrabbit, etc.

You should typically not be dependent on portal-impl at all. You seem to instantiate a GroupImpl object for your test - I'd recommend to create a mock/dummy at most: Your own tests typically don't want to use too much of the implementation of the underlying platform. And while portal-impl is part of the portal's implementation, it's not made available to client code. You'll only access the implementation indirectly through portal-kernel.

Also, with this migration, you should check first if your customization is still required, or if you can utilize some of the new built-in features. Best case, you can get rid of your custom code and rather rely on something that the platform provides, that you don't need to maintain any more.

What exactly goes wrong is hard to say without the code. But the code should be fairly minimal.