将输出文件重定向到maven中的目录

时间:2014-08-12 23:16:14

标签: java maven

如何将输出文件重定向到maven中的自定义目录?让我说我的输出目录是测试,我想要所有的应用程序输出文件写入测试。我怎么在maven中这样做?

3 个答案:

答案 0 :(得分:1)

如果这些"输出文件"由您的测试生成,只需在创建这些资源时定义类似target/test之类的前缀或类似的东西。

或者,看看this,如果这是你需要的,但不知道如何解释。

答案 1 :(得分:0)

通过"输出目录",我认为你的意思是"目标"包含所有构建工件和生成代码的目录。

<build>
    <directory>${buildDirectory}</directory>
</build>

答案 2 :(得分:0)

以下内容如何:

<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.3</version>
        </plugin>
    </plugins>
    <resources>
        <resource>
        <directory>src/main/java</directory>
            <includes>
                <include> **/*.properties</include>
            </includes>
        </resource>
    </resources>
    ...
</build>

如何使用: Copy-maven-plugin

<plugin>
    <groupId>com.github.goldin</groupId>
    <artifactId>copy-maven-plugin</artifactId>
    <version>0.2.5</version>
    <executions>
        <execution>
            <id>create-archive</id>
            <phase>package</phase>
            <goals>
                <goal>copy</goal>
            </goals>
            <configuration>
                <resources>
                    <!-- ~~~~~~~~~~~~~~ -->
                    <!-- Copy resources -->
                    <!-- ~~~~~~~~~~~~~~ -->
                    <resource>
                        <targetPath>${project.build.outputDirectory}/scripts</targetPath>
                        <directory>${project.basedir}/src/main/resources</directory>
                        <includes>
                            <include>bat/setenv*.bat, bat/wrapper*.bat, bat/install*.bat, bat/uninstall*.bat</include>
                            <include>lib/core</include>
                            <include>*.jar</include>
                        </includes>
                    </resource>
                    <resource>
                        <targetPath>${project.build.outputDirectory}/scripts</targetPath>
                        <directory>${project.basedir}/conf</directory>
                        <include>resources, scripts</include>
                    </resource>
                    <!-- ~~~~~~~~~~~~~~ -->
                    <!-- Copy directory -->
                    <!-- ~~~~~~~~~~~~~~ -->
                    <resource>
                        <targetPath>${project.build.outputDirectory}/spring</targetPath>
                        <directory>${project.basedir}/src/main/resources/spring</directory>
                    </resource>
                    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                    <!-- Copy "compile" dependencies -->
                    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                    <resource>
                        <targetPath>${project.build.outputDirectory}/lib</targetPath>
                        <dependency>
                            <includeScope>compile</includeScope>
                        </dependency>
                    </resource>
                    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
                    <!-- Unpack two data archives -->
                    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
                    <resource>
                        <targetPath>${project.build.outputDirectory}/data</targetPath>
                        <dependencies>
                            <dependency>
                                <groupId>someData</groupId>
                                <artifactId>dependencyArchive</artifactId>
                            </dependency>
                            <dependency>
                                <groupId>anotherData</groupId>
                                <artifactId>dependencyArchive</artifactId>
                            </dependency>
                        </dependencies>
                        <unpack>true</unpack>
                    </resource>
                    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                    <!-- Create final archive and attach it as Maven artifact -->
                    <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                    <resource>
                        <targetPath>${project.build.directory}/zipName.zip</targetPath>
                        <directory>${project.build.outputDirectory}</directory>
                        <pack>true</pack>
                        <attachArtifact>true</attachArtifact>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>