Maven 构建 Jar 包中的资源

Maven Build Jar with Resource in Package

我正在尝试使用 Maven 构建一个 Jar,我想将我的一个资源直接放入 Java 包中,但我不知道该怎么做。例如,如果我的 Maven 项目看起来像这样

src/main/java
--com
---company
----application
-----database


src/main/resources
--config.xml

我想要一个 config.xml 最终在 com/company/application/database 中的罐子。知道怎么做吗?我正在使用 eclipse 4.5.1 和 maven 3.3

如果您想将 config.xml 放入 com/company/application/database 中,您可以在 resources 下创建该目录并将 config.xml 放入其中。

cd src/main/resources
mkdir -p com/company/application/database
mv config.xml /com/company/application/database/

我想通了。这是我的 pom.xml:

中的内容
<build>
    <plugins>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.outputDirectory}/com/company/app/common/tablebeans/shared</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/src/main/resources</directory>
                                <includes>
                                    <include>**/*hibernate*xml</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>