简体   繁体   English

Spring DevTools 未包含在 spring-boot-maven-plugin 打包的 fat jar 中

[英]Spring DevTools not included in the fat jar packaged with spring-boot-maven-plugin

I am trying to create a fat jar using spring-boot plugin.我正在尝试使用 spring-boot 插件创建一个胖罐子。 But it keeps giving me NoClassDefFound exception.但它一直给我 NoClassDefFound 异常。

I have the following in my pom:我的 pom 中有以下内容:

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <mainClass>${start-class}</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

I package it using我用它打包

mvn clean package spring-boot:repackage

,i also tried ,我也试过

mvn clean install spring-boot:repackage

When I try to run it later with当我稍后尝试运行它时

java -jar myapp.jar

It gives me the following exception它给了我以下异常

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/devtools/filewatch/FileChangeListener
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getDeclaredMethod(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.devtools.filewatch.FileChangeListener
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 7 more

I tried everything i've found online as a solution and it doesn't work.我尝试了我在网上找到的所有解决方案,但它不起作用。

Added this:添加了这个:

<excludeDevtools>false</excludeDevtools>

To the spring-boot-maven-plugin:到 spring-boot-maven-plugin:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <excludeDevtools>false</excludeDevtools>
                    <mainClass>${start-class}</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Dev tools is excluded by default.默认情况下排除开发工具。

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

相关问题 spring-boot-maven-plugin 不会创建 fat jar - spring-boot-maven-plugin doesn't create fat jar 运行 spring-boot-maven-plugin 配置的胖 JAR 时出现 ClassNotFoundException - ClassNotFoundException when running fat JAR configured by spring-boot-maven-plugin 在 spring-boot-maven-plugin 打包的 jar 中使用 ClassPath.getTopLevelClasses() 查找类 - Finding classes with ClassPath.getTopLevelClasses() in jar packaged by spring-boot-maven-plugin spring-boot-maven-plugin 创建具有依赖项的 jar - spring-boot-maven-plugin create jar with dependencies spring-boot-maven-plugin创建的jar通过使用classpath运行 - spring-boot-maven-plugin created jar run by using classpath 无法在 spring-boot-maven-plugin 中分叉 - Unable to fork in spring-boot-maven-plugin spring-boot-maven-plugin:加载在哪里? - spring-boot-maven-plugin: where it is loaded? Spring Boot app通过spring-boot-maven-plugin运行,但不是jar - Spring Boot app runs through the spring-boot-maven-plugin, but not the jar 尽管在 spring-boot-maven-plugin 中配置了排除,但日志依赖项仍包含在 lib 文件夹中 - Logging dependencies still included in lib folder despite exlusion being configured in spring-boot-maven-plugin 插件org.springframework.boot:spring-boot-maven-plugin? - Plugin org.springframework.boot:spring-boot-maven-plugin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM