java - Maven复制资源

标签 java maven

在配置文件文件夹中的资源中,有一个配置文件,具体取决于应采用的配置文件并将其放入资源根目录中

其实我也遇到过

  1. 他把它放在项目本身中,而不是原来的 jar 中
  2. 当您第二次收集该文件时
  3. 这样 jar 中的文件夹本身就不会掉落

    <plugins>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>${maven-resources-plugin.version}</version>
            <executions>
                <execution>
                    <id>copy-properties</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/src/main/resources</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/src/main/resources/profile/${profile.dir}</directory>
                                <includes>
                                    <include>server.properties</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>${maven-ejb-plugin.version}</version>
            <configuration>
                <filterDeploymentDescriptor>true</filterDeploymentDescriptor>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                    <addMavenDescriptor>false</addMavenDescriptor>
                </archive>
                <ejbVersion>3.0</ejbVersion>
            </configuration>
        </plugin>
    </plugins>
    

请告诉我哪里错了? 在哪个插件中配置maven-ejb-plugin或maven-resources-plugin

我有src/main/recoursces/profile/

  • serverA/server.properties
  • serverB/server.properties
  • serverC/server.properties

我想要 jar - 它没有文件夹配置文件 - 并且拥有一个 server.properties

最佳答案

我不确定我是否理解你的问题。我认为资源阶段package不正确,它应该位于前一个阶段,例如process-resources

这里有Maven Lifecycle Reference

process-resources:将资源复制并处理到目标目录中,准备打包。
打包:获取已编译的代码并将其打包为其可分发的格式,例如 JAR。

关于java - Maven复制资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46300470/

相关文章:

java - 对于涉及复杂Android功能的游戏,选择unity还是native java

java - 修复自定义 OpenNLP NER 模型

java - 像在 Java 中旋转硬币一样旋转图像

java - Groovy 和 maven - 从 src/main/groovy 编译源代码

java - 使用 Spring 和 Intellij 时无法解析 MVC View

java - 为什么图像在通过套接字写入发送时不显示在客户端浏览器中?

c# - 如果 catch 和 finally block 都抛出异常会发生什么?

java - 如何从对象列表的每个对象中删除一个字段?

java - Maven 将同级项目的二进制文件作为打包的一部分包含在内

maven - IntelliJ 使用 .class 而不是模块的 .java