【Java】maven多项目资源共享

本文介绍两种在Maven项目中配置资源共享的方法。方案一通过修改<resources>标签来包含外部配置文件;方案二利用maven-remote-resources-plugin插件实现跨项目资源的共享。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

方案一:

<resources>
            <resource>
                <!-- <directory>${project.parent.relativePath}/../../config</directory> -->
                <directory>${basedir}/../../config</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.txt</include>
                    <!-- <include>**/*.config</include>
                    <include>key/*.*</include> -->
                </includes>
                <!-- <targetPath>resources</targetPath> -->
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <!-- <include>**/*.xml</include>
                <filtering>true</filtering> -->
            </resource>
        </resources>

 

方案二:

资源端:
<!-- https://stackoverflow.com/questions/2362652/excluding-classes-in-maven-checkstyle-plugin-reports -->
                <!-- https://stackoverflow.com/questions/14117709/configuring-maven-to-generate-output-outside-the-project-directory -->
                <!-- https://blog.sonatype.com/2008/04/how-to-share-resources-across-projects-in-maven/ -->
                <!-- http://maven.apache.org/plugins/maven-remote-resources-plugin/examples/sharing-resources.html -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-remote-resources-plugin</artifactId>
                    <version>${maven-remote-resources-plugin.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>bundle</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <includes>
                            <include>**/*</include>
                        </includes>
                    </configuration>
                </plugin>
引用端:
<plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-remote-resources-plugin</artifactId>
                    <version>${maven-remote-resources-plugin.version}</version>
                    <configuration>
                        <resourceBundles>
                            <resourceBundle>com.laplace:laplace:${project.version}</resourceBundle>
                        </resourceBundles>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>process</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值