Maven 打包时丢失properties文件

来源:互联网 发布:淘宝浏览app赚佣金 编辑:程序博客网 时间:2024/05/21 08:57

今天在打包项目war文件的时候,突然发现居然每个action包里面的properties文件都没打进来,在网上看了半天终于找到解决方法。

问题:maven执行package命令打包时,src/main/java路径下的properties文件偶尔丢失

解决方式:pom.xml中加入resources配置

<build><finalName>sx-user-cernter-provider</finalName><!--install 后包的名字--><sourceDirectory>src/main/java</sourceDirectory><!-- class文件 的目录 --><resources><resource><!-- instrall 时会过滤掉 不需要打包的文件--><targetPath>${project.build.directory}/classes/META-INF/spring</targetPath><directory>src/main/resources/META-INF/spring</directory><filtering>true</filtering><excludes><exclude>*.xml</exclude><exclude>*.properties</exclude></excludes></resource><resource><!--配置需要所有的java文件--><directory>src/main/java</directory><excludes><exclude>**/*.java</exclude></excludes></resource></resources><plugins><!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><configuration><classesDirectory>target/classes/</classesDirectory><excludes><exclude>**/provider.properties</exclude><exclude>*.properties</exclude><exclude>**/datasource/**</exclude><exclude>*.xml</exclude></excludes><archive><addMavenDescriptor>false</addMavenDescriptor></archive></configuration></plugin><!-- 拷贝依赖的jar包到lib目录 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><executions><execution><id>copy</id><phase>package</phase><goals><goal>copy-dependencies</goal></goals><configuration><outputDirectory>${project.build.directory}/lib</outputDirectory></configuration></execution></executions></plugin>            <plugin>                <artifactId>maven-assembly-plugin</artifactId>                <configuration>                    <descriptor>src/main/assembly/assembly.xml</descriptor>                </configuration>                <executions>                    <execution>                        <id>make-assembly</id>                        <phase>package</phase>                        <goals>                            <goal>single</goal>                        </goals>                    </execution>                </executions>            </plugin></plugins></build>

说明:

首先了解maven生命周期如下:

生命周期阶段目标process-resourcesresources:resourcescompilecompiler:compileprocess-test-resourcesresources:testResourcestest-compilecompiler:testCompiletestsurefire:testpackagewar:warinstallinstall:installdeploydeploy:deploy

经测试,

1.当pom中不增加resources配置时,

  • 执行process-resources,class文件夹下只包含src/main/resources下的文件
  • 执行compile,class文件夹下包含src/main/resources下的文件与src/main/java下的*.class文件,丢失src/main/java下的*.properties文件

2.当pom中增加resources配置时

  • 执行process-resources,class文件夹下只包含src/main/resources下的文件与src/main/java下的*.properties文件
  • 执行compile,class文件夹下包含src/main/resources下的文件与src/main/java下的*.class文件与*.properties文件

0 0
原创粉丝点击