我在Eclipse上使用Spring Boot和Maven,并在Eclipse上构建Maven。当我尝试运行jar文件时,出现错误。
我在pom.xml的manifast和spring boot插件中添加了mainclass,并清理并重建了Maven。我在src / main / java / com.bacnet.monitoring文件夹中有BaCnetMonitoringSystemApplication.java文件。我已经在类上注释了@SpringBootApplication,我的lib文件夹中有一些jar文件可供编译。
<?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应用程序中的更新。 (这意味着找不到或加载基本类BaCnetMonitoringSystemApplication)
原因:java.lang.ClassNotFoundException:com.bacnet.monitoring.BaCnetMonitoringSystemApplication
答案 0 :(得分:0)
您可以尝试几种解决方案:
添加到pom.xml
<properties>
<start-class>com.bacnet.monitoring.BaCnetMonitoringSystemApplication</start-class>
</properties>
尝试在Eclipse中更新项目:右键单击项目-> Maven->更新项目。然后重新运行该项目。
清理您的Maven缓存并重新运行:mvn dependency:purge-local-repository