Maven和maven-resources-plugin

时间:2012-11-18 11:03:05

标签: maven

我想使用maven-resources-plugin将资源复制到另一个目录。

我的资源目录具有以下结构:

log4j.xml
xml
  |_ resource-1
  |_ resource-n

我想只将log4.xml复制到输出目录。这是我的插件代码:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <outputDirectory>${glassfish.conf}</outputDirectory>
            <resources>
                <resource>
                    <directory>${conf.location}</directory>
                    <includes>
                        <include>**/log4j.xml</include>
                    </includes>
                    <excludes>
                        <exclude>**/xml/*</exclude>
                    </excludes>
                </resource>
            </resources>
        </configuration>
        <executions>
            <execution>
                <id>copy-log4j-to-glassfish</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
            </execution>
        </executions>
</plugin>

但是所有都被复制到输出目录(log4j.xml和xml目录)。

我试过

<resource>
    <directory>${conf.location}</directory>
        <excludes>
            <exclude>**/xml/*</exclude>
        </excludes>
</resource>

或者

<resource>
    <directory>${conf.location}</directory>
    <includes>
        <include>**/log4j.xml</include>
    </includes>                         
</resource>

即使

<resource>
    <directory>${conf.location}</directory>
    <excludes>
        <exclude>**/*</exclude>
    </excludes>
</resource>

但目录的所有内容都包括在内......有什么问题?

谢谢

1 个答案:

答案 0 :(得分:6)

回答Andrew Logvinov:

使用这样的插件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>copy-log4j-to-glassfish</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${glassfish.conf}</outputDirectory>
                <resources>
                    <resource>
                        <directory>${conf.location}</directory>
                        <includes>
                            <include>log4j.xml</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

它运行良好,只复制了log4j.xml。

现在使用此插件配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>copy-log4j-to-glassfish</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <outputDirectory>${glassfish.conf}</outputDirectory>
        <resources>
            <resource>
                <directory>${conf.location}</directory>
                <includes>
                    <include>log4j.xml</include>
                </includes>
            </resource>
        </resources>
    </configuration>
</plugin>

我的所有文件都被复制了。

我检查xsd here configuration阻止可以在plugin内部还是在execution内部,因此我不知道这是一个插件错误还是这个误解我。