SpringBoot项目eclipse运行正常maven install打包启动后报错ClassNotFoundException

parent的pom.xml

    <groupId>cn.licoygroupId>
    <artifactId>parentartifactId>
    <version>0.1version>
    <packaging>pompackaging>

    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>1.5.6.RELEASEversion>
    parent>

    <modules>
        <module>../restmodule>
        <module>../servicemodule>
    modules>

    <dependencies>
        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
            <version>1.16.16version>
        dependency>
    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                <configuration>
                    <mainClass>cn.licoy.rest.RestApplicationmainClass>
                    <layout>ZIPlayout>
                configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackagegoal>
                        goals>
                    execution>
                executions>
            plugin>
        plugins>
    build>

project>

直接在IDEA里面运行SpringBoot启动类是可以正常访问的,但是使用mvn install打包后,报出如下错误:

java.lang.ClassNotFoundException: cn.licoy.service.entity.User
        at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_131]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_131]
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94) ~[rest-0.1.jar:0.1]

其中,Springboot启动包是rest包,当中引用了service包中的User类,在打包之后的rest.jar里面lib目录下有service.jar,但是一访问就找不到类

解决方法:要给被依赖的module的pom.xml中添加

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                <configuration>
                    <classifier>execclassifier>
                configuration>
            plugin>
        plugins>
    build>

 

你可能感兴趣的:(SpringBoot项目eclipse运行正常maven install打包启动后报错ClassNotFoundException)