1

我想使用 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>

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

谢谢

4

1 回答 1

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块configuration可以在标签内pluginexecution标签内,所以我不知道这是插件错误还是对我的误解。

于 2012-11-19T08:53:45.033 回答