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

问题描述 投票:6回答:3

我正在使用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
3个回答
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>

4
投票

两种选择:

  • 使用现代插件,自动添加源dirs(maven-jaxb2-plugin does this)。
  • 对qazxsw poi使用类似build-helper-maven-plugin的东西。

免责声明:我是上面提到的add source folders的作者。


0
投票

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

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

你去吧! Eclipse将添加生成文件的文件夹。这是添加生成的文件后我的项目结构的样子。

© www.soinside.com 2019 - 2024. All rights reserved.