maven默认src下的xml,properties文件不打包到classes文件夹下

一、第一种是建立src/main/resources文件夹,将xml,properties等资源文件放置到这个目录中。maven工具默认在编译的时候,会将resources文件夹中的资源文件一块打包进classes目录中。

这时候注意把resources设置成resource目录,已经是就不用管了。

二、第二种解决方式是配置maven的pom文件配置,在pom文件中找到<build>节点,添加下列代码: 

<build>
        <resources>
            <resource>
                <!-- 这里是放在 src/main/java-->
                <directory>src/main/resources/fxml</directory>
                <includes>
                    <include>**/*.properties</include>

                    <!-- **/表示只要在资源目录下的.json文件都被加载到classes文件中,

                        不管是否在资源目录子目录中-->

                    <include>**/*.json</include>
                    <include>**/*.xml</include>
                    <include>**/*.fxml</include>
                    <include>**/fxml/*.fxml</include>
                    <!-- 如果想要弄个包名专门放fxml文件,像上一行这样添加设置 -->
                    <!-- 之后,使用getResource("fxml/xx.fxml")这样子 -->
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>

</build> 

 

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
maven-replacer-plugin插件主要用于文件内容替换,不太适合用于生成文件并输入内容。但是,你可以使用maven-resources-plugin插件生成文件并将内容写入文件中。 以下是一个示例: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <id>generate-file</id> <phase>process-resources</phase> <goals> <goal>resources</goal> </goals> <configuration> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>example.txt</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 在这个例子中,我们使用maven-resources-plugin插件在process-resources阶段生成文件并将内容写入文件中。 首先,在configuration标签中设置outputDirectory为${project.build.outputDirectory},这将指定生成的文件输出到项目的target目录下。 接下来,在resources标签中,我们指定要生成的文件名为example.txt,这个文件名必须位于src/main/resources目录下。同时,我们将filtering属性设置为true,这将启用Maven的资源过滤机制,可以在文件中使用Maven的属性占位符。 然后,在执行过程中,maven-resources-plugin插件将会在target/classes目录下生成一个名为example.txt的文件,并将文件中的所有Maven属性占位符替换为实际的值。 如果你需要在生成的文件中写入特定的内容,可以在example.txt文件中使用Maven属性占位符,然后在pom.xml中使用<properties>标签定义属性值。 例如,在example.txt文件中写入如下内容: ``` Hello, ${username}! ``` 在pom.xml中定义属性值: ```xml <properties> <username>world</username> </properties> ``` 这将生成一个名为example.txt的文件文件中的"Hello, ${username}!"将被替换为"Hello, world!"。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值