首页 > 解决方案 > 没有资源的 jar 应该如何工作?(排除资源的 maven-shade-plugin)

问题描述

我有一个没有任何文档的遗留代码(假设是 100% 工作)。这段代码由几个独立的服务组成,它们执行一些任务(比如使用 RabbitMQ,将一些记录插入 Postgres DB,等等)。maven-shade-plugin 配置中 pom.xml 中的每个服务都具有从生成的 jar 中排除的资源文件夹。像这样:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>${maven-shade-plugin-version}</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>log4j2.xml</exclude>
                            <exclude>application.properties</exclude>
                            <exclude>update.sql</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
        </execution>
    </executions>
</plugin>

结果,当我尝试运行任何这样的 jars ( with java -jar any_of_my_jars.jar) 时,它们会失败,因为它们需要 application.properties 和所有其他资源才能运行。

所以问题是:应该是我错过了一些东西。我要么应该以其他方式运行它们,要么应该将它们部署在某个地方。有人可以向我解释一下这些罐子如何用作工作罐子吗?

标签: javamavenmicroservices

解决方案


推荐阅读