【问题标题】:maven can't find generated sources (mvn clean install)maven 找不到生成的源(mvn clean install)
【发布时间】:2015-03-02 15:58:01
【问题描述】:

我几个小时前刚遇到这个问题,直到现在它似乎一直有效。

我通过以下方式在我的 pom 中生成代码:

 <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>

            <configuration>
                <sourceDestDir>${basedir}/target/generated/java</sourceDestDir>
                <keep>true</keep>
                <verbose>true</verbose>
                <extension>true</extension>
                <wsdlDirectory>${basedir}/src/main/resources/META-INF</wsdlDirectory>
            </configuration>

            <executions>
                <execution>
                    <id>ecad-ws</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <wsdlFiles>
                            <wsdlFile>wsdl/ECadDocumentServiceWSDL.wsdl</wsdlFile>
                        </wsdlFiles>
                        <staleFile>${project.build.directory}/jaxws/stale/wsdl.ECadDocumentServiceWSDL.done</staleFile>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaDirectory>${basedir}/src/main/resources/META-INF/xsd</schemaDirectory>
                    <packageName>be.fgov.health.ecad.xmlstructure</packageName>
                <outputDirectory>${basedir}/target/generated/java</outputDirectory>
            </configuration>
        </plugin> 

我在我的项目中使用这些生成的类。 如果我然后执行“右键单击 -> maven -> clean”+“右键单击 -> maven -> 安装”,一切正常。 但是当我运行 mvn clean install -DskipTest=true 时,maven 找不到生成的源。我已经被困了几个小时,并且无法真正找到它。 (顺便说一句,在 Eclipse 中这样做)

编辑:

刚刚发现以下内容:如果我删除第二个插件(由 xsd 生成),我不会收到任何错误。如果我将所有使用这些生成类的代码都放在 c 的注释中。

另一个编辑:

我已经更改了 jaxb 生成的 outputDirectory,现在它可以工作了。谁能解释一下为什么它不能与 wsimport 位置相同?

【问题讨论】:

  • 尝试使用 -Dmaven.test.skip=true
  • 这完全一样 ofc :)
  • @GregD 它不完全相同:-DSkipTests 是 surefire 的一个功能,而 -Dmaven.test.skip 是 maven itsel 的一个功能,但它们的行为是类似的方式。
  • 我提到:“它给了我完全相同的错误”
  • 您是否已经尝试过按照您所说的那样做一个“干净的项目”……

标签: java eclipse maven


【解决方案1】:

默认情况下,jaxb2-maven-plugin 在将生成的类放入之前删除outputDirectory

您可以使用属性clearOutputDir 控制此行为。您的插件配置将如下所示:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>xjc</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <schemaDirectory>${basedir}/src/main/resources/META-INF/xsd</schemaDirectory>
        <packageName>be.fgov.health.ecad.xmlstructure</packageName>
        <outputDirectory>${basedir}/target/generated/java</outputDirectory>
        <clearOutputDir>false</clearOutputDir>
    </configuration>
</plugin> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 2023-03-03
    • 2013-05-12
    • 2023-03-17
    相关资源
    最近更新 更多