【问题标题】:Add generated-sources as source folder to Eclipse将生成的源作为源文件夹添加到 Eclipse
【发布时间】:2014-10-23 11:15:37
【问题描述】:

我正在使用 maven-jaxb-plugin 来生成基于 xsd 文件的类文件源:

<plugin>
                <groupId>com.sun.tools.xjc.maven2</groupId>
                <artifactId>maven-jaxb-plugin</artifactId>
                <version>1.1.1</version>
                <executions>
                    <execution>
                        <id>jaxb-xsd-constants</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generatePackage>com.mypackage</generatePackage>
                            <schemaDirectory>${basedir}/src/main/resources/xsd/mylist</schemaDirectory>
                            <includeSchemas>
                                <includeSchema>mylist.xsd</includeSchema>
                            </includeSchemas>
                            <strict>true</strict>
                        </configuration>
                    </execution>                    
                </executions>
            </plugin>

但是我需要将这些文件夹添加为源文件夹,以便 Eclipse 加载编译它们:

如何使用插件或其他方法将文件夹添加为源文件夹?无需手动添加这些文件夹。

【问题讨论】:

    标签: java eclipse maven jaxb


    【解决方案1】:

    尝试使用这个 maven 插件..

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.1</version>
                    <executions>
                        <execution>
                            <id>add-source</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>add-source</goal>
                            </goals>
                            <configuration>
                                <sources>
                                    <source>target/generated-sources/xjc</source>
                                </sources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    

    【讨论】:

      【解决方案2】:

      两种选择:

      • 使用现代插件,例如自动添加源目录 (maven-jaxb2-plugindoes this)。
      • 使用类似 buld-helper-maven-plugin 的东西来add source folders

      免责声明:我是上述maven-jaxb2-plugin 的作者。

      【讨论】:

      • 当我使用 build-helper-maven-plugin 时,我需要针对当前项目的 pom 运行 mvn eclipse:eclipse。这是预期的行为吗?如果我不运行 eclipse:eclipse 那么该目录不会添加为源文件夹。
      • @blue-sky 我个人使用 m2eclipse 和 maven-jaxb2-plugin,自动在 eclipse 中工作。我从不运行 mvn eclipse:eclipse。
      【解决方案3】:

      我正在努力通过 vert.x 代理服务添加一些生成的文件。以下是我在 Eclipse 中将生成的文件添加到我的项目中所遵循的步骤。

      1. 右键单击您生成的文件夹(在您的情况下为 mylist
      2. 点击构建路径
      3. 然后点击用作源文件夹

      然后就可以了! Eclipse 将添加已生成文件的文件夹。这是添加生成的文件后我的项目结构的样子。

      【讨论】:

        猜你喜欢
        • 2011-11-01
        • 2015-01-01
        • 2013-01-15
        • 1970-01-01
        • 2015-04-05
        • 1970-01-01
        • 2012-07-09
        • 2015-01-29
        • 1970-01-01
        相关资源
        最近更新 更多