Java maven编译器插件:如何告诉它源目录的位置?

Java maven编译器插件:如何告诉它源目录的位置?,java,eclipse,maven,jaxb,xjc,Java,Eclipse,Maven,Jaxb,Xjc,我有一个使用Eclipse开发的Java项目。下面是我的POM.XML文件: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache

我有一个使用Eclipse开发的Java项目。下面是我的
POM.XML
文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mbm</groupId>
    <artifactId>properties</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Properties</name>
    <description>Define and process program arguments</description>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.2.11</version>
        </dependency>
    </dependencies>

    <pluginRepositories>
        <pluginRepository>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
                <updatePolicy>daily</updatePolicy>
            </snapshots>
            <id>apache-maven-repository</id>
            <name>Apache Maven repository maven2</name>
            <url>https://repo.maven.apache.org/maven2</url>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <id>xjc</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- Configuration for version 2.2 -->
                    <arguments>
                        <argument>-Xlocator</argument>
                    </arguments>
                    <outputDirectory>${basedir}/target/generated-sources/jaxb</outputDirectory>
                    <packageName>com.mbm.properties.jaxb</packageName>
                    <sources>
                        <source>${basedir}/src/main/java/com/mbm/properties/schema/Properties.xsd</source>
                    </sources>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sablecc-maven-plugin</artifactId>
                <version>2.4-SNAPSHOT</version>
                <configuration>
                    <sourceDirectory>${basedir}/src/main/java/com/mbm/properties/grammar</sourceDirectory>
                    <outputDirectory>${basedir}/target/generated-sources/sablecc</outputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
注意源根。第一个:

C:\Users\mbmas\u 000\workspace\Properties\src\main\java

我并不感到惊讶。Maven希望Java源代码位于该目录中是有道理的

后两行确实让我感到惊讶:

C:\Users\mbmas\u 000\workspace\Properties\target\generated sources\sablecc
C:\Users\mbmas\u 000\workspace\Properties\target\generated sources\annotation

我从未在POM中指定这些额外的目录(我甚至不知道如何做,因为
inputDirectory
maven编译器插件接受的一个明显缺失的参数)。Maven怎么知道要包括这些?还有,为什么不呢

C:\Users\mbmas\u 000\workspace\Properties\target\generated sources\jaxb

也包括在内,因为这是jaxb2 maven插件的指定输出目录

如何修改此POM文件以使

C:\Users\mbmas\u 000\workspace\Properties\target\generated sources\jaxb


是否包含在Java编译阶段?

您正在使用的特定插件-
org.codehaus.mojo:sablecc maven plugin
-碰巧添加了
作为编译源根。这就是为什么
maven编译器插件
能够找到它的原因

您可以使用
org.codehaus.mojo:build helper maven plugin
添加其他源代码,如中所述:


...
org.codehaus.mojo
构建助手maven插件
3.2.0
添加源
生成源
添加源
一些目录
...
[INFO] Changes detected - recompiling the module!
[DEBUG] Classpath:
[DEBUG]  C:\Users\mbmas_000\workspace\Properties\target\classes
[DEBUG]  C:\Users\mbmas_000\.m2\repository\org\glassfish\jaxb\jaxb-core\2.2.11\jaxb-core-2.2.11.jar
[DEBUG]  C:\Users\mbmas_000\.m2\repository\javax\xml\bind\jaxb-api\2.2.12-b140109.1041\jaxb-api-2.2.12-b140109.1041.jar
[DEBUG]  C:\Users\mbmas_000\.m2\repository\org\glassfish\jaxb\txw2\2.2.11\txw2-2.2.11.jar
[DEBUG]  C:\Users\mbmas_000\.m2\repository\com\sun\istack\istack-commons-runtime\2.21\istack-commons-runtime-2.21.jar
[DEBUG] Source roots:
[DEBUG]  C:\Users\mbmas_000\workspace\Properties\src\main\java
[DEBUG]  C:\Users\mbmas_000\workspace\Properties\target\generated-sources\sablecc
[DEBUG]  C:\Users\mbmas_000\workspace\Properties\target\generated-sources\annotations
[DEBUG] Command line options:
[DEBUG] -d C:\Users\mbmas_000\workspace\Properties\target\classes -classpath C:\Users\mbmas_000\workspace\Properties\target\classes;C:\Users\mbmas_000\.m2\repository\org\glassfish\jaxb\jaxb-core\2.2.11\jaxb-core-2.2.11.jar;C:\Users\mbmas_000\.m2\repository\javax\xml\bind\jaxb-api\2.2.12-b140109.1041\jaxb-api-2.2.12-b140109.1041.jar;C:\Users\mbmas_000\.m2\repository\org\glassfish\jaxb\txw2\2.2.11\txw2-2.2.11.jar;C:\Users\mbmas_000\.m2\repository\com\sun\istack\istack-commons-runtime\2.21\istack-commons-runtime-2.21.jar; -sourcepath C:\Users\mbmas_000\workspace\Properties\src\main\java;C:\Users\mbmas_000\workspace\Properties\target\generated-sources\sablecc;C:\Users\mbmas_000\workspace\Properties\target\generated-sources\annotations; -s C:\Users\mbmas_000\workspace\Properties\target\generated-sources\annotations -g -nowarn -target 1.8 -source 1.8
<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>some directory</source>
                ...
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>