在Eclipse IDE中使用maven / m2e从.proto自动生成Java [英] Automatically generate Java from .proto with maven/m2e in Eclipse IDE
问题描述
对于我的团队,我想配置maven / eclipse构建以从 *。proto
文件自动生成Java代码(在使用 gRPC )。目前需要运行 mvn generate-source
或 mvn protobuf:compile
(如插件使用页面)。或者什么是相同的添加运行配置来调用maven目标编译
。
For my team, I'd like to configure maven/eclipse build to automatically generate Java code from *.proto
files (in a project that uses gRPC). Currently one needs to run mvn generate-source
or mvn protobuf:compile
(as in plugin usage page). Or what is the same add Run configuration to invoke maven goal compile
.
每当Eclipse Maven项目被刷新(< kbd> Alt + F5 )或IDE重新启动,项目重建,但不会出现在 target / generated
中,因此转动项目变成红色。所以需要生成和刷新项目( F5 )。 UPDATE Eclipse需要在 .clathpath
文件中配置源文件夹。
Whenever Eclipse Maven project is refreshed (Alt+F5) or IDE is restarted, project is rebuilt but without what should appear in target/generated
, thus turning project into red. So one need to generate and refresh project (F5). UPDATE Eclipse has needed source folders configured in .clathpath
file.
我知道应该是m2e连接器,但是我只能找到一个 https://github.com/masterzen/m2e-protoc-connector对于最旧的Google 的插件com.google.protobuf.tools:maven-protoc-plugin
,甚至目前在 https://github.com/grpc/grpc-java
As I know that should be m2e connector, but I could only find one https://github.com/masterzen/m2e-protoc-connector for the oldest Googles plugin com.google.protobuf.tools:maven-protoc-plugin
, that is even not mentioned currently at https://github.com/grpc/grpc-java
我们使用完全引用/推荐的
We use exactly referenced/recommended
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
即:
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.1.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
相关:
- 链接到Eclipse中生成的Java protobuf代码
- 看着这个,但该作者正在使用其他较旧的,现在不支持插件:由protobuf生成的代码(与Maven Project Builder相关)导致的Eclipse构建循环
PPS该插件< a href =https://github.com/igor-petruk/protobuf-maven-plugin =nofollow noreferrer> https://github.com/igor-petruk/protobuf-maven-plugin 但是,如 https://github.com/os72/protoc-jar-maven-插件
- Linking to generated Java protobuf code in Eclipse
- looked at this but that author was using other older, not supported now plugin : Eclipse build loop caused by protobuf generated code (related to Maven Project Builder)
P.P.S That plugin https://github.com/igor-petruk/protobuf-maven-plugin however has continuation as https://github.com/os72/protoc-jar-maven-plugin
推荐答案
for protobuf-行家-插件
for protobuf-maven-plugin
感谢sergei-ivanov在 https://github.com/xolstice/protobuf-maven-plugin/issues/16 ,它给了链接 https://github.com/trustin/os-maven-plugin#issues-with- eclipse-m2e-or-other-ides :
Thanks to sergei-ivanov answer in https://github.com/xolstice/protobuf-maven-plugin/issues/16, that gave link https://github.com/trustin/os-maven-plugin#issues-with-eclipse-m2e-or-other-ides :
需要下载os-maven-plugin-xxxFinal.jar(您的pomx中的版本) .ml),并将其放入< ECLIPSE_HOME> / plugins
目录中。
One need to download os-maven-plugin-x.x.x.Final.jar (the version as in your pomx.ml) and put it into the <ECLIPSE_HOME>/plugins
directory.
之后Eclipse将生成源包括在Maven-update项目之后...( Alt + F5 ),但不是在Project - > Build(或默认自动构建)后。还有在IDE开始它不会编译。
After that Eclipse will generate source on project clean, including after Maven -update project... (Alt+F5), but not after Project -> Build (or with default Build Automatically). Also on IDE start it will not compile.
是的,这是不合逻辑的:
Yes, that is illogical:
清理将生成和编译Java源
但是
项目 - Build不会。
PS提高了错误507412
这篇关于在Eclipse IDE中使用maven / m2e从.proto自动生成Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!