简体   繁体   English

在控制台中从 maven 运行编译的 jar 时,我收到 java.lang.NoClassDefFoundError

[英]I'm getting a java.lang.NoClassDefFoundError when running compiled jar from maven in console

I had built a jar file ( mvn clean install ) yesterday and it executed perfectly but when I'm trying to build a jar file, it's getting built with no errors but with a much lesser space occupied.我昨天构建了一个 jar 文件( mvn clean install )并且它执行得很好,但是当我尝试构建一个 jar 文件时,它的构建没有错误,但占用的空间要小得多。 And, when I try to run the jar file I'm getting the error:而且,当我尝试运行 jar 文件时,出现错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
    at com.mukundmadhav.springboot.springboot.SpringbootApplication.main(SpringbootApplication.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication

My pom.xml:我的 pom.xml:

<?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 https://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.2.4.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.mukundmadhav.springboot</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
    <start-class>com.mukundmadhav.springboot.springboot.SpringbootApplication</start-class>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.6</version>
                <configuration>
                    <workingDirectory>frontend</workingDirectory>
                    <installDirectory>target</installDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <configuration>
                            <nodeVersion>v8.9.4</nodeVersion>
                            <npmVersion>5.6.0</npmVersion>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm run build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <configuration>
                            <target>
                                <copy todir="${project.build.directory}/classes/public">
                                    <fileset dir="${project.basedir}/frontend/build" />
                                </copy>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </pluginManagement>
</build>

when I run mvn -v :当我运行 mvn -v 时:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\opt\apache-maven-3.6.3\bin\..
Java version: 1.8.0_171, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_171\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

The project runs when I try to run application from eclipse.当我尝试从 Eclipse 运行应用程序时,该项目会运行。 I've rechecked my system variables and the class path for start class.我已经重新检查了我的系统变量和开始类的类路径。 I can't figure out what eaxctly the issue is.我无法弄清楚问题是什么。

I figured out what was happening.我想通了发生了什么。 I had enclosed my plugins in a <pluginManagement/> and therefore they weren't getting read.我已经将我的插件包含在<pluginManagement/> ,因此它们没有被读取。 Removing the enclosure fixed the issue.移除外壳解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“主”java.lang.NoClassDefFoundError 中的异常:使用控制台运行时。 可能与 Maven 相关 - Exception in thread "main" java.lang.NoClassDefFoundError: when running with console. Possibly Maven-related 为什么在使用POI jar的jar时出现java.lang.NoClassDefFoundError - Why I'm Getting java.lang.NoClassDefFoundError while using jar which use poi jars 运行jar文件时抛出java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError thrown when running jar file java.lang.NoClassDefFoundError:从Scala运行JAR时 - java.lang.NoClassDefFoundError : while running JAR from Scala 运行jar时java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError while running jar java.lang.NoClassDefFoundError + ant-运行一个jar - java.lang.NoClassDefFoundError + ant - running a jar 使用 maven 不断获取 java.lang.NoClassDefFoundError - keep getting java.lang.NoClassDefFoundError with maven 尝试从jar实例化类时出现java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError when trying to instantiate class from jar 使用Maven时出现Java.lang.NoClassDefFoundError - Java.lang.NoClassDefFoundError when using Maven 在使用1.6 JDK编译的项目中运行JDK 1.7编译的jarfile时出现java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError when running jdk 1.7 compiled jarfile inside project compiled with 1.6 jdk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM