简体   繁体   中英

java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

I am getting this exception java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7 and java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache ) when i run the spring boot application

I am using below tools

STS 3.9.10 release
Open JDK 14 64 bit
Spring boot 2.2.5

It worked fine with oracle jdk but its failing to run with openjdk. I am not using any groovy libs. This is maven based spring boot project.

How do you run the application? It's probably because you use Gradle as the build system and JDK14 and the Gradle version is old. Reference: https://github.com/gradle/gradle/issues/10248

If you use Gradle Wrapper then refer to $PROJECT_ROOT/gradle/wrapper/gradle-wrapper.properties . The property distributionUrl should be: distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip

If it's an older version then change it, run ./gradlew clean build and try again.

I solved it by editing the gradle-wrapper.properties file inside the gradle folder. (Not.gradle):

Change this line, from:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip

to:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

rebuild and it's ok.

In the file android/gradle/wrapper/gradle-wrapper.properties , ensure that the distributionUrl is as follows:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip

Note: If you installed jdk 14

Got the same issue on a Maven & SpringBoot project, no Gradle whatever.

The dependency to org.codehaus.groovy is probably transitive through spring-cloud-contract-verifier. Run mvn dependency:tree to view the whole dependency tree.

I got it fixed by upgrading the spring-cloud-contract-maven-plugin version to 2.2.3-RELEASE

Check that your project is running with Java 14 even though it is prepared for Java 8.

My IntelliJ Idea was giving the same error when trying to execute a Gradle task which was running perfectly in command line with JDK 8. The ItelliJ Idea project default JDK was 14 though.

in my case, the JRE version used in the Run Configuration was different than the target JDK version in the pom.xml

SpringBoot_Run_Config

I resolve this problem when integrated Facebook 7.19.2 and Google play Games 0.10.09 .

In my case JDK and SDK using (and other in Edit/Preferences/External -> Tools-Android ) default paths Unity:

JDK

C:/ProgramFiles/Unity/Hub/Editor/2019.2.12f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\OpenJDK\Windows

SDK

C:/Program Files/Unity/Hub/Editor/2019.2.12f1/Editor/Data/PlaybackEngines/AndroidPlayer\SDK

In Environmental Variables(System Proporites/Advanced) added next:

Find(or click new variable under User Variables)

  • JAVA_HOME and add root JDK path.

  • JAVA_BIN and add path JDK/bin

  • JAVA_LIB and add path JDK/lib

Also, add these paths in System Variables to variable "Path".

Do not use SDK from default Unity and JDK from not Unity default

Then Restart Unity(and better PC).

Then in Editor Unity - Assets/Play -> Service -> Resolve/Android -> Resolver/Force -> Resolve

All Work fine.

In my case the combination was IntelliJ 2020.2, Kotlin 1.3.72, Maven 3.6.1 and SpringBoot 2.2.1 application. No Gradle used at all in the project.

Somehow IntelliJ had switched to use OpenJDK14 - when reverting back to OpenJDK11 everything started to work again.

are you using some third party library that brings in dependencies?依赖项? If yes, you can try and replace the required groovy dependencies with the most current releases yourself.

In my case it was the , so I did this: ,所以我这样做了:

    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-groovy-dsl</artifactId>
        <version>2.1.1</version>
        <exclusions>
            <exclusion>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-sql</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy</artifactId>
        <version>3.0.3</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-sql</artifactId>
        <version>3.0.3</version>
    </dependency>

If you using Android Studio 4.0 or up and having Errors like below

    Cause: invalid type code: 17
    Cause: invalid type code: fe
    Cause: invalid type code: 13
java.lang.NoClassDefFoundError: Could not initialize class

Or

Its says that something wrong with JDK then Follow below steps to resolve the error.

Step 1 : First delete .gradle and .idea folder from project directory and restart Android Studio. Make sure it's gone from recycle bin.

Step 2 : Go to Project Structure

项目结构

Step 3: Select SDK Location from the left panel on Project Structure window.

Step 4: Go to JDK Location and click on down arrow then select the jre instead of jdk

C:\Program Files\Android\Android Studio\jre

JDK 位置

And it will Solve the errors. Rebuild the project

Note: jre come with the android studio 4 installation not sure about the older version.

This solution work for me.

I fixed this by adding Apache Groovy 2.4.7 in pom.xml

in my maven Spring Boot project, I solve the problem by adding dependency:

        <!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy -->
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy</artifactId>
        <version>3.0.8</version>
    </dependency>

I solved this by selecting Installed JRE path in window => preferences => java => installed JRE => remve existing & select from local directory.

Make sure you have java_home variable set in environmental variable

For Maven users, Please follow the below steps to resolve this issue

  1. You should place rest-assured before the JUnit dependency declaration in your pom.xml / build.gradle in order to make sure that the correct version of Hamcrest is used.
  2. Add the following dependencies to your pom.xml
<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>3.0.8</version>
    <type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy -->
<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy</artifactId>
    <version>3.0.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-json -->
<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-json</artifactId>
    <version>3.0.8</version>
</dependency>

Hope this will fix your issue. It works for me. Instruction mentioned at step#1 copies from Rest Assured official site. Thanks

I simply changed the gradle version for the project to the newer version.

升级截图

PS. I use kotlin

4 things in IntelliJ to check:

  • Your Project Structure -> Project -> SDK and Language level
  • Settings -> Build,Execution,Deployment -> Build Tools -> Gradle, look at Gradle JVM
  • Settings -> Build,Execution,Deployment -> Compiler -> Java Compiler
  • Your build.gradle, the Java { sourceCompatibility and targetCompatibility }

Make them all agree on the JDK / language level and it should be fine

If you are looking for similar solution as @godsim shared, but for gradle liquabase plugin, then modify your configuration section in build.gradle to exclude liquabase's groovy dependency:

configurations {
    ...
    liquibaseRuntime.exclude group: "org.codehaus.groovy"
}

and then manually add groovy in dependencies section:

dependencies {
    ...
    liquibaseRuntime('org.liquibase:liquibase-core:3.8.1')
    liquibaseRuntime('org.codehaus.groovy:groovy-all:3.0.3')
    liquibaseRuntime 'org.postgresql:postgresql'
    liquibaseRuntime('org.liquibase:liquibase-groovy-dsl:2.1.2')
    liquibaseRuntime('org.liquibase.ext:liquibase-hibernate5:3.10.2')
    liquibaseRuntime('org.springframework.boot:spring-boot-starter-data-jpa')
    liquibaseRuntime sourceSets.main.output
    ...
}

This issue is solved for me only when I updated compileSdkVersion and targetSdkVersion to 30 with minSdkVersion 19

Was getting the error when using old versions of spotbugs-maven-plugin plugin and the corresponding spotbugs maven dependency.

Fixed by upgrading both to 4.2.0 .

I have met a similar problem. But my error message is not exactly the same.

I got some ideas from Tarmo and checking the gradle version, eclipse version and the JDK it use.

My error message is:

> Could not open cp_init generic class cache for initialization script 'D:\xxx\TestingEnv\Dev1\eclipse\.metadata\.plugins\org.eclipse.buildship.core\init.d\eclipsePlugin.gradle' (C:\Users\xxx\.gradle\caches\5.6\scripts\6a5krabdzij62jglcll542e66\cp_init\cp_init8a51e2ebf3f7f8302cfbbb80ea3d4b3d).
   > Could not initialize class org.codehaus.groovy.classgen.Verifier

I have using SpringToolSuite4 Version: 4.9.0.RELEASE Build Id: 202012132054 for development.

I have 2 projects. Project A and Project B.

Project A, works fine without gradle problem Under this project, gradle> wrapper > gradle-wrapper.propties My distributionUrl is: distributionUrl=https://services.gradle.org/distributions/gradle-4.8-bin.zip

Later, I have another project B and the setting is:

Project B: Under this project, gradle> wrapper > gradle-wrapper.propties My distributionUrl is: distributionUrl=https://services.gradle.org/distributions/gradle-5.6.2-bin.zip

When I select 'refresh gradle' in the IDE, Project B keeps failing build and output the error mentioned above.

I have no clues on it until I found the answer from Tarmo.

Things I have done:

  1. Try to change the distributionUrl=https://services.gradle.org/distributions/gradle-6.3-bin.zip -The error message changes to other. (Seems we are on the right way)
  2. Check the JDK version, which Eclipse using to start the itself.
  • Under menu bar > Help > About Spring Tool Suite 4 > Installation Details > press 'Configuration Tab > searching for a row start with -vm
  • It was originally pointing th OpenJDK, then I changed it to pointing to JDK 1.8 at my local machine. It failed to start since it is not supported the older version of JDK.
  1. I downloaded the older version of STS sts-4.4.1.RELEASE
  • Now, I import the project again, press 'refresh gradle', it works fine and the gradle task shows properly in the IDE.
  1. In the sts-4.4.1.RELEASE folder, adding an entry into SpringToolSuite4.ini to pointing to use JDK 1.8 at my local PC.
C:/Program Files/Java/jdk1.8.0_301/bin/javaw.exe

-If not specify, it would use the openjdk to start with by default. It is a good practice to specify the version we use.

Appendix SpringToolSuite4.ini https://wiki.eclipse.org/Eclipse.ini

It was coming for me in Idea, and got resolved after setting JAVA_HOME in.zshrc and.bash_profile, source both the files and restart the Idea.

export JAVA_HOME="<Path to JDK just above bin " # For e.g it was "/opt/homebrew/opt/openjdk@11" in my Mac machine could be /Contents/Home based on you have used homebrew or manually gunzipped

It can also happen because you forgot to indicate your Android SDK via local.properties in a freshly cloned Android Project.

If you are on Windows operating system and using Android Studio, you should run Android Studio as Administrator.

Move to JDK 11, it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM