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

Syd*_*ney 7 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>
Run Code Online (Sandbox Code Playgroud)

Sea*_*oyd 7

你应该能够这样做:

<build>
    <outputDirectory>${project.build.directory}/myclasses</outputDirectory>
</build>
Run Code Online (Sandbox Code Playgroud)


Syd*_*ney 5

目标文件夹必须存在。您可以使用 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>
Run Code Online (Sandbox Code Playgroud)

  • 是的,但是如果您打算这样做,您最好也使用 ant 运行编译器。 (2认同)