views:

22

answers:

1

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  A: 

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.

Jon Skeet
Thanks for teh answer! I think the 2nd solution sounds better. However, when I try to include the source directory from Properties->Java Build Path, under Source Eclipse doesn't let me link to an arbitrary system file. Does the generated code directory *has* to be placed under the project directory?
recipriversexclusion
@recipriversexclusion: I can't remember whether there's any way of including an external directory... I don't think I've ever needed to. That's why I said that the first option would make it easier to keep the generated source away from your project :)
Jon Skeet