【maven】如何把配置文件打包到jar中

我在把一个项目打包成jar发布时,希望将配置文件一起打包到jar中,如何做?

方法1. 把配置文件放到src/main/resources目录下,maven-jar-plugin会自动把该目录下的资源文件打包进去。

http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html#classesDirectory


classesDirectory:

Directory containing the classes and resource files that should bepackaged into the JAR.

    Type: java.io.File
    Required: Yes
    Default: ${project.build.outputDirectory}


src/main/resources/目录下的文件和目录都会打包到jar中。
 
    
                org.apache.maven.plugins
                maven-jar-plugin
                
                    
                        make-a-jar
                        package
                        
                            jar
                        
                    
                
            

使用一个test-jar

src/test/resources/ 目录下的文件和目录都会打包到test-jar中。            
     
                org.apache.maven.plugins
                maven-jar-plugin
                
                    
                        make-test-jar
                        package
                        
                            test-jar
                        
                    
                
            



方法2: 用http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html#includes


include:

List of files to include. Specified as fileset patterns which arerelative to the input directory whose contents is being packagedinto the JAR.
  • Type: java.lang.String[]
  • Required: No

你可能感兴趣的:(maven)