maven-compiler-plugin如何更改类目标目录

时间:2012-06-21 15:26:52

标签: maven

默认情况下,maven编译器插件将编译后的类放入${project.build.directory}/classes。我想把它们放进${project.build.directory}/myclasses。参数-d更改已编译类的目标。我配置了插件但是出现了错误:javac: directory not found: C:\home\target/myclasses

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.5</source>
        <target>1.5</target>
        <showDeprecation>true</showDeprecation>
        <compilerArguments>
            <d>${project.build.directory}/myclasses</d>
        </compilerArguments>
    </configuration>
</plugin>

2 个答案:

答案 0 :(得分:7)

你应该能够这样做:

<build>
    <outputDirectory>${project.build.directory}/myclasses</outputDirectory>
</build>

答案 1 :(得分:3)

目标文件夹必须存在。您可以使用ant任务创建它:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>createClassesDir</id>
            <phase>process-resources</phase>
            <configuration>
                <tasks>
                    <mkdir dir="${project.build.directory}/myclasses" />
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>