Skip to content

java.lang.NoClassDefFoundError #556

Closed

Description

@demanLiu

[provide a description of the issue]
I use spring-boot 2.1.3.RELEASE ,when I run application
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: net/bytebuddy/NamingStrategy$SuffixingRandom$BaseNameResolver

mvn dependency:tree | grep -10 byte-buddy

[INFO] +- org.springframework.boot:spring-boot-test:jar:2.1.3.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.3.RELEASE:test
[INFO] +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] | +- net.minidev:json-smart:jar:2.3:test
[INFO] | | - net.minidev:accessors-smart:jar:1.2:test
[INFO] | | - org.ow2.asm:asm:jar:5.0.4:test
[INFO] | - org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] +- org.assertj:assertj-core:jar:3.11.1:test
[INFO] +- org.mockito:mockito-core:jar:2.23.4:test
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.9.10:test
[INFO] | +- net.bytebuddy:byte-buddy-agent:jar:1.9.10:test

HibernateJpaConfiguration.class needs byte-buddy ,but byte-buddy's scope is "test",So application can not find byte-buddy at runtime,then I remove scope in pom.xml, it's ok

   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <!-- <scope>test</scope> -->
    </dependency>

But when I execute "mvn clean package && java -jar xxx.jar " ,it is ok
at the same time ,it‘s also ok using IntelliJ IDEA

Environment
Operating System:archlinux
JDK version: 1.8.0_202
Visual Studio Code version:1.32.3
Java extension version:
Language Support for Java(TM) by Red Hat 0.42.1
Maven for Java 0.15.2

Activity

  1. yaohaizh commented on Apr 3, 2019

    @yaohaizh
    Contributor

    Jinbo Wang (@testforstephen) Yan Zhang (@Eskibear) Could you help investigate this problem?

  2. demanLiu commented on Apr 15, 2019

    @demanLiu
    Author
        <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.pingan.urbantech.bim.web.BimCloudWebApplication</mainClass>
                    <layout>ZIP</layout>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中 -->
                            <goal>build-info</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    
    
    java -jar  -verbose:class   bim-cloud-web/target/bim-cloud-web.jar  | grep -10 bytebuddy  
    

    [Loaded net.bytebuddy.implementation.bytecode.Removal from jar:file:/home/lh/Project/JAVA/bim-cloud/bim-cloud-web/target/bim-cloud-web.jar!/BOOT-INF/lib/byte-buddy-1.9.10.jar!/]

    spring-boot-maven-plugin package bytebuddy into jar ,but vscode-java-debug can not found bytebuddy in command "java -cp xxx" ,so I add this Item in .classpath .

       <classpathentry kind="lib" path="/home/lh/.m2/repository/net/bytebuddy/byte-buddy/1.9.10/byte-buddy-1.9.10.jar"/>
    

    I am not clear about the Differences between vscode-java-debug and spring-boot-maven-plugin

  3. testforstephen commented on May 5, 2019

    @testforstephen
    Contributor

    vscode-java-debug doesn't include the test scope library when calculating the class paths. If you want it in a normal application, you must remove the test scope tag.

  4. testforstephen commented on Aug 26, 2019

    @testforstephen
    Contributor

    midkiller (@demanLiu) Is this issue still reproducing in the latest java debugger?

  5. demanLiu commented on Sep 22, 2019

    @demanLiu
    Author

    Jinbo Wang (@testforstephen) It seems all right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions