Spring DevTools不包含在与spring-boot-maven-plugin打包在一起的胖子罐中 [英] Spring DevTools not included in the fat jar packaged with spring-boot-maven-plugin

查看:91
本文介绍了Spring DevTools不包含在与spring-boot-maven-plugin打包在一起的胖子罐中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用spring-boot插件创建一个胖子.但是它一直给我NoClassDefFound异常.

I am trying to create a fat jar using spring-boot plugin. But it keeps giving me NoClassDefFound exception.

我的pom中有以下内容:

I have the following in my 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>

我使用

mvn clean package spring-boot:repackage

,我也尝试过

mvn clean install spring-boot:repackage

当我稍后尝试使用它运行时

When I try to run it later with

java -jar myapp.jar

它给了我以下例外情况

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.

推荐答案

添加了此内容:

<excludeDevtools>false</excludeDevtools>

到spring-boot-maven-plugin:

To the 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.

这篇关于Spring DevTools不包含在与spring-boot-maven-plugin打包在一起的胖子罐中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆