Linking to generated Java protobuf code in Eclipse

走远了吗. 提交于 2019-12-31 03:33:09

问题


Here's the workflow that I'm trying to build

  • compile my proto files using a script, putting the generated src in a specified directory
  • link to the generated classes in Eclipse
  • compile my project

I am easily able to do this for C++ using Eclipse CDT: In my project I choose File->New->Other and choose File under General. Then I click on Advanced and select link to system file.

I haven't discovered how to do this for Java, though. Once answer here suggests creating another project with the generated code and make that a dependency to my project. This works but seems redundant.

Is there a way to directly link the generated protobuf Java classes to my project?


回答1:


Well Java doesn't really have a "link" phase. Your two options are really:

  • Build the generated code outside Eclipse, and then add a reference to the relevant directory or jar file
  • Include the generated code within Eclipse (e.g. by having a source path which includes the directory containing your generated code) and get Eclipse to build it along with the rest of your code.

I suspect that the first option will make it easier to keep the generated code well away from your real source, but the second option may make it easier to browse the generated source, and package everything up.



来源:https://stackoverflow.com/questions/4044891/linking-to-generated-java-protobuf-code-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!