Maven - Add directory to classpath while executing tests

后端 未结 6 1154
北海茫月
北海茫月 2020-12-02 15:29

The Junits I have in my project need to load property files from the classpath. How can I specify the directory of those property files so that Maven will set that in the cl

6条回答
  •  萌比男神i
    2020-12-02 16:11

    The maven-resources-plugin has a copy-resources goal that will allow you to copy resources. For example:

      
        org.apache.maven.plugins
        maven-resources-plugin
        2.6
        
          
            additional-resources
            process-test-resources
            
              copy-resources
            
            
              ${project.build.testOutputDirectory}
              
                
                  ${project.basedir}/conf
                
              
            
          
        
      
    

    This will copy the contents of the conf folder in the base of your project to the target/test-classes folder (unless you modified project.build.testOutputDirectory) which will be added to the classpath during your unit tests.

提交回复
热议问题