0
votes

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

1
src/main/java/com.bacnet.monitoring normally must be src/main/java/com/bacnet/monitoring - user85421
For starters stop mixing Spring Boot versions. You have Spring Boot 2.1.4 but are using the maven plugin from 2.0.3. That is trouble waiting to happen. Remove the version tag from the plugin. Now this makes me wonder what other versions you have in your dependencies list. Also remove the maven-assembly-plugin the Spring Boot plugin takes care of that, and you are basically destroying that. - M. Deinum

1 Answers

0
votes

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