将生成的源作为源文件夹添加到 Eclipse
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25568339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add generated-sources as source folder to Eclipse
提问by blue-sky
I'm using the maven-jaxb-plugin to generate class file sources based on xsd files :
我正在使用 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>
But I then need to add these folders as a source folder in order for Eclipse to load compile them :
但是我需要将这些文件夹添加为源文件夹,以便 Eclipse 加载编译它们:
How can the folder be added as a source folder using the plugin or some other method ? Instead of having to manually add these folders.
如何使用插件或其他方法将文件夹添加为源文件夹?而不必手动添加这些文件夹。
回答by Xstian
Try to use this maven plugin..
尝试使用这个 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>
回答by lexicore
Two options:
两种选择:
- use a modern plugin like which adds source dirs automatically (
maven-jaxb2-plugin
does this). - use something like a buld-helper-maven-plugin to add source folders.
Disclaimer:I am the author of the maven-jaxb2-plugin
mentioned above.
免责声明:我是上述内容的作者maven-jaxb2-plugin
。
回答by Abdul Waheed
I was struggling to add some generated files through vert.x proxy service. Here are the steps which I followed to add generated files to my project in Eclipse.
我正在努力通过 vert.x 代理服务添加一些生成的文件。以下是我在 Eclipse 中将生成的文件添加到我的项目所遵循的步骤。
- Right click on your generated folder (in your case mylist)
- Click on Build Path
- Then click on Use as Source Folder
- 右键单击您生成的文件夹(在您的情况下mylist)
- 点击构建路径
- 然后单击用作源文件夹
and there you go! Eclipse will add the folder which has generated files. This is how my project structure looks like after adding the generated files.
你去吧!Eclipse 将添加生成文件的文件夹。这是添加生成的文件后我的项目结构的样子。