作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Google Protocol Buffers 为我的项目生成一些 Java 类。使用 Maven 2 及其“antrun”插件,这些类在编译前新鲜生成,输出到 target/generated-sources 并在构建期间放在类路径中。因此从 POM 构建项目是没有问题的。
但是,Eclipse 不知道如何解析生成的类,因为它所在的文件夹在开发过程中似乎并不位于 IDE 的类路径中。我正在使用 m2eclipse 并让它为我管理依赖项,所以我希望 Maven 能够处理这个问题。
如何获得生成代码的 IDE 支持(代码完成等)?
最佳答案
m2eclipse 支持这个。首先,将路径添加到构建路径:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
其次,向 m2e 添加对此的支持:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>parse-version</goal>
<goal>add-source</goal>
<goal>maven-version</goal>
<goal>add-resource</goal>
<goal>add-test-resource</goal>
<goal>add-test-source</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
如果您的 Eclipse 安装已安装“org.eclipse.m2e.discovery.lifecyclemapping.buildhelper.xml”插件,则可能不需要第二步。该插件可通过 Window -> Preferences -> Maven -> Discovery 获得。目前,这在 Eclipse Kepler 中不起作用,因此,我获取了 JAR(从 Catalog URL 中显示的 xml 链接)并从 org.eclipse.m2e.discovery.lifecyclemapping.buildhelper.xml
中提取了片段。用手。
关于eclipse - 如何让 Eclipse 解析使用 Maven 2 生成的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1192596/
我是一名优秀的程序员,十分优秀!