我按照这里给出的步骤https://www.javatpoint.com/spring-maven-project
我的pom.xml
...
<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>
<groupId>com.sample</groupId>
<artifactId>spring-boot-simple</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<start-class>com.sample.SpringBootSimpleApp</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
我的申请类
package com.sample;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootSimpleApp {
public static void main(String[] args){
try{
Class.forName("com.sample.SpringBootSimpleApp");
SpringApplication.run(SpringBootSimpleApp.class, args);
}
catch(Exception e){
e.printStackTrace();
}
}
}
Buid很好我可以通过Eclipse RunAs生成jar文件 - &gt; Maven Build ..目标是干净安装
当我使用eclipse作为java应用程序运行时,我收到以下错误
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.sample.SpringBootSimpleApp.main(SpringBootSimpleApp.java:18)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
我正在使用eclipse neon.3,工作区配置了备用jre - 安装了jdk 1.8,工作区编译器级别为1.8。
请帮助您运行应用程序类。
答案 0 :(得分:1)
我猜想Maven在下载时已经损坏了一个jar文件。尝试运行mvn dependency:purge-local-repository
,然后重建您的应用程序