首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maven:读取属性文件并复制资源

Maven:读取属性文件并复制资源
EN

Stack Overflow用户
提问于 2016-12-02 08:58:47
回答 1查看 1.4K关注 0票数 0

我喜欢一些场景,即读取一个属性文件,并根据属性文件的值创建文件夹并将资源从某个目录复制到它。

代码语言:javascript
复制
properties-file: xyz.properties

CLIENTLIST=A,B

我想在maven中执行以下步骤。

代码语言:javascript
复制
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有可能吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-05 07:25:12

我是用两个插件做的,

代码语言:javascript
复制
<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/@item@/</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. 并创建每个循环中的文件夹,并将资源复制到创建的文件夹中。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40928224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档