将generated-sources作为源文件夹添加到Eclipse

时间:2014-08-29 12:30:28

标签: java eclipse maven jaxb

我正在使用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>

enter image description here

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

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

3 个答案:

答案 0 :(得分:6)

尝试使用此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>

答案 1 :(得分:4)

两个选项:

  • 使用现代插件,自动添加源目录(maven-jaxb2-plugin does this)。
  • 使用类似buld-helper-maven-plugin的内容到add source folders

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

答案 2 :(得分:0)

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

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

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

相关问题