2016-12-02 66 views
0

我進入了一些場景,即讀取屬性文件,並根據屬性文件的值創建文件夾,並將資源從某個目錄複製到它。Maven:讀取屬性文件和複製資源

properties-file: xyz.properties 

CLIENTLIST=A,B 

我想在maven中執行以下步驟。

1. From above properties file pom should read the property. 
2. In loop I want to create folders by name A and B. 
3. After creating folder i want to copy some resources into it. 
    ex: after creating folder A , want to copy some resource files from x/y/z directory. 

在maven中可能嗎?

回答

0

我這樣做是使用夫妻插件,

<plugins> 
<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>properties-maven-plugin</artifactId> 
    <version>1.0.0</version> 
    <executions> 
    <execution> 
    <id>read property file</id> 
    <phase>install</phase> 
    <goals> 
    <goal>read-project-properties</goal> 
    </goals> 
    <configuration> 
    <files> 
     <file>${basedir}/dirOne/xyz.properties</file> 
    </files> 
    </configuration> 
    </execution> 
    </executions> 
</plugin> 

<plugin> 
    <groupId>com.soebes.maven.plugins</groupId> 
    <artifactId>iterator-maven-plugin</artifactId> 
    <version>0.3</version> 
    <executions> 
    <execution> 
    <phase>install</phase> 
    <goals> 
     <goal>iterator</goal> 
    </goals> 
    <configuration> 
     <content>${CLIENTLIST}</content> 
     <pluginExecutors> 
     <pluginExecutor> 
     <plugin> 
<artifactId>maven-resources-plugin</artifactId> 
<version>2.6</version> 
</plugin> 
<goal>copy-resources</goal> 
<configuration> 
    <outputDirectory>${basedir}/dirTwo/@[email protected]/</outputDirectory> 
    <resources> 
    <resource> 
     <directory>${basedir}/src/main/resources/</directory> 
     <includes> 
     <include>**/*.xml</include> 
     <include>**/*.properties</include> 
     </includes> 
     <excludes><exclude>**/*.cmd</exclude></excludes> 
    </resource> 
    </resources> 
    </configuration> 
    </pluginExecutor> 
    </pluginExecutors> 
    </configuration> 
    </execution> 
    </executions> 
    </plugin> 
    </plugins> 
</build> 

我已經使用屬性讀取,迭代器和複製的資源插件來獲得我所需要的。

  1. 首先我讀取屬性文件。
  2. 在從屬性文件讀取的循環迭代值中。
  3. 並創建每個文件夾循環並將資源複製到創建的文件夾。