Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用SpringBootMaven插件时无法将资源文件夹放入jar_Java_Maven_Spring Boot - Fatal编程技术网

Java 使用SpringBootMaven插件时无法将资源文件夹放入jar

Java 使用SpringBootMaven插件时无法将资源文件夹放入jar,java,maven,spring-boot,Java,Maven,Spring Boot,我试图构建一个运行SpringBoot的可执行jar,但是我无法将SpringXML从resources文件夹中获取到jar中。看起来我的outputDirectory出错了。定义它的正确方法是什么,以便将它打包到jar中 这是我的pom文件 <build> <resources> <resource> <directory>${basedir}/src/main/resources/my-resou

我试图构建一个运行SpringBoot的可执行jar,但是我无法将SpringXML从resources文件夹中获取到jar中。看起来我的outputDirectory出错了。定义它的正确方法是什么,以便将它打包到jar中

这是我的pom文件

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources/my-resources</directory>
            <includes>
                <include>*xml</include>
            </includes>
        </resource>
    </resources>

    <plugins>

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>netexchange.exchange.main.ExchangeMain</mainClass>
                    </manifest>
                </archive>
                <outputDirectory>${basedir}/target</outputDirectory>
                <finalName>Matcher-with-config</finalName>
                <addResources>true</addResources>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <defaultGoal>install</defaultGoal>
    <directory>${basedir}/target</directory>
</build>

${basedir}/src/main/resources/my resources
*xml
org.springframework.boot
springbootmaven插件
真的
netexchange.exchange.main.ExchangeMain
${basedir}/目标
配置匹配器
真的
包裹
重新包装
安装
${basedir}/目标

因此我想出了一个解决方案,将特定的资源复制到“src/main/resources”文件夹中。Spring boot build自动包含该文件夹中的所有文件,然后您可以使用注释“@ImportResource({”classpath:config.xml“})”导入它们

我更新的pom如下所示:

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources/bitcoin-ethereum</directory>
            <includes>
                <include>*xml</include>
            </includes>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.2</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/src/main/resources</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/src/main/resources/matcher</directory>
                                <includes>
                                    <include>*xml</include>
                                </includes>
                            </resource>
                            <resource>
                                <directory>${basedir}/src/main/resources/common</directory>
                                <includes>
                                    <include>*xml</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>netexchange.exchange.main.ExchangeMain</mainClass>
                    </manifest>
                </archive>
                <outputDirectory>${basedir}/target</outputDirectory>
                <finalName>Matcher</finalName>
                <addResources>true</addResources>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <defaultGoal>install</defaultGoal>
    <directory>${basedir}/target</directory>
</build>

${basedir}/src/main/resources/bitcoin以太坊
*xml
maven资源插件
3.0.2
复制资源
编译
复制资源
${basedir}/src/main/resources
${basedir}/src/main/resources/matcher
*xml
${basedir}/src/main/resources/common
*xml
org.springframework.boot
springbootmaven插件
真的
netexchange.exchange.main.ExchangeMain
${basedir}/目标
匹配器
真的
包裹
重新包装
安装
${basedir}/目标

为什么会有Spring XML文件?您是否尝试过完全不包含任何这种配置,让默认的魔法发挥作用?我的目标是最终从同一个源创建多个具有不同spring XML文件的JAR,所以我需要它来发挥作用,而您想要“不同的spring XML文件”为什么?您似乎还没有读过引导配置系统(它相当全面,几乎肯定会以更灵活的安排涵盖您的用例,特别是外部化配置),因为每个jar需要不同的bean。我将阅读更多关于外部化配置的内容