简体   繁体   中英

java.lang.ClassNotFoundException on spring boot and maven build

I'm using spring boot and maven on eclipse, and I build maven on eclipse. When I try to run my jar file, there comes error.

I added mainclass in manifast and spring boot plugin in my pom.xml, and clean and rebuild maven. And I have BaCnetMonitoringSystemApplication.java file at src/main/java/com.bacnet.monitoring folder. I already annoted @SpringBootApplication on class, I have some jar files in my lib folder to compile with.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.bacnet.monitoring</groupId>
    <artifactId>BACnetMonitoringSystem</artifactId>
    <version>1.1.3</version>
    <packaging>jar</packaging>
    <name>BACnetMonitoringSystem</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <!-- dependency -->
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.0.3.RELEASE</version>
                <configuration>
                    <mainClass>com.bacnet.monitoring.BaCnetMonitoringSystemApplication</mainClass>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.bacnet.monitoring.BaCnetMonitoringSystemApplication</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

        </plugins>

    </build>

</project>

java -jar BACnetMonitoringSystem-1.1.3-jar-with-dependencies.jar 오류: 기본 클래스 com.bacnet.monitoring.BaCnetMonitoringSystemApplication 을(를) 찾거나 로드할 수 없습니다. (it means could not find or load basic class BaCnetMonitoringSystemApplication)

cause: java.lang.ClassNotFoundException: com.bacnet.monitoring.BaCnetMonitoringSystemApplication

You can try several solutions:

  1. Add to pom.xml

    <properties> <start-class>com.bacnet.monitoring.BaCnetMonitoringSystemApplication</start-class> </properties>

  2. Try update the project in your Eclipse: Right Click the project -> Maven -> Update Project. Then Re-run the project.

  3. Clean your maven cache and rerun: mvn dependency:purge-local-repository

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