sparrow sparrow - 26 days ago 8
Java Question

Can't create a new object in Springboot application

I have a Spring boot web application. I have a another project, a jar file. I added this jar file to web application and created a new object from the jar file. There is no compilation error. but when ever I run I am getting run time exception java.lang.ClassNotFoundException. I don't know what's going wrong. Any help will be appreciated

Answer

Assuming you're using Maven, you're probably missing the Spring Boot Maven Plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${spring-boot.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Without this you'll just get a small JAR with just your classes. With this plugin you get a "full" jar which contains all the dependencies you need.

Comments