3

我通过直接修改我的pom.xml文件将 Swagger Codegen 添加到我的 Eclipse 项目中:

<plugin>
    <!--
        Plugin that provides API-first development using swagger-codegen to
        generate Spring-MVC endpoint stubs at compile time from a swagger definition file
    -->
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>${swagger-codegen-maven-plugin.version}</version>
    <executions>
        <execution>
                <id>generate-swagger-javaclient</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <inputSpec>src/main/resources/swagger/remote-api.json</inputSpec>
                    <language>java</language>
                    <apiPackage>com.myproj</apiPackage>
                    <modelPackage>com.myproj.model</modelPackage>
                    <generateSupportingFiles>true</generateSupportingFiles>
                    <generateApiTests>false</generateApiTests>
                    <configOptions>
                        <dateLibrary>java8</dateLibrary>
                    </configOptions>
                    <library>resttemplate</library>
                </configuration>
            </execution>
        </executions>
    
</plugin>

如果我运行 Maven 更新或 Mavengenerate-sources目标,我会在我的 Eclipse 项目/target/generated-sources/swagger/src文件夹中生成所有的人工制品。

但是,Eclipse 无法识别它们。我应该像一些普通人一样手动编辑我的 Eclipse 构建路径,还是 Eclipse 应该自动识别这个新的源文件夹?

4

4 回答 4

2

在 Eclipse 4.9.0 (2018-09) 中,我必须将 generate-sources 文件夹添加为项目的源文件夹,如下所示:

  1. 打开“导航器”视图
  2. 浏览到目标/生成源(或生成源的任何文件夹)。
  3. 右键单击该文件夹
  4. 单击“构建路径”->“用作源文件夹”

菜单树截图

不解决“生命周期配置未涵盖插件执行”的问题。

于 2019-05-14T09:19:29.643 回答
2

build-helper-maven-plugin如果此插件本身不支持,您可以使用将生成的源添加到构建路径。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${project.basedir}/target/generated-sources/</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
于 2018-08-29T06:51:24.417 回答
1

目前的答案是,将生成的源文件夹添加到构建路径似乎是强制性的。

于 2018-03-20T13:41:10.800 回答
0

Ctrl+Shift+R

打开“打开资源”对话框。除了消息行“输入资源名称....”之外,还有一个下拉选项。当你点击它时,你会得到“显示状态”、“显示派生来源”等选项。

您必须确保选中“显示派生来源”。Eclipse 也将开始显示 swagger 生成的工件。

于 2019-07-19T12:18:03.327 回答