3

Can anyone help me to write a plugin for eclipse in c++?


@weekens and @celavek thanks for the information. I am going through JNI and will try to implement it.

@celavek: what kind of master/control we have to do? is it riskier to handle in C++ and java interface.

My requirement is to add my own property in Preference pages in Java they are using Propertypages package to do that. But how to do it in C++?

ChrisF
  • 134,786
  • 31
  • 255
  • 325
Ambuja
  • 197
  • 1
  • 12
  • If you're asking because your Java knowledge is a little thin, I'd strongly suggest you try to write it all in Java. Learning a new language is a great way to strengthen your programming skills. – Gyan aka Gary Buyn Jul 26 '11 at 09:13
  • @Gary Buyn: It is not only learning thing. we have two parts(one as plugin and one as stand alone applicaiton) in the project and it has to be developed in CDT. And also yes, i am new to Java. – Ambuja Jul 26 '11 at 10:15
  • Fair enough. Just thought I'd put it out there. – Gyan aka Gary Buyn Jul 26 '11 at 10:58
  • It turns out you are trying to write a preference page that will show up when your clients use your plugins with CDT? And your preference controls what? Could you please update your question with this information? – Paul Webster Jul 26 '11 at 11:21
  • @Paul Webster: Yes, client use our plugin with CDT. My preference control the client's propect properties. Is it necessary to give about clients expectation in the question? If, yes i'll give it. – Ambuja Jul 27 '11 at 08:56

2 Answers2

3

The Eclipse framework is written in Java and the whole plugin infrastructure is built around that, which basically means that most of the times you would have to write your plugin in Java(there are other language possibilities to work with the JVM, see comments and the note about Jython below). However there are possibilities to have some of your plugin functionality written in C++(or other languages) and then bridge the C++ interface to Java which will make it available in your plugin. For that you could try using JNI, MS COM, Mozilla XPCOM, CORBA(you could try omniORB) or Swig. I have worked with XPCOM and Swig for a previous job to make this kind of interfacing possible - we had a debugger engine written in C++ and we were exposing the interface/functionality to Eclipse Java plugins via XPCOM. I'm sure there are others alternatives out there e.g. Jython - I've been using this one to write some small scripts in Python and then expose that directly in Eclipse.

Be aware that this kind of interfacing can get very involved sometimes - you would have to have a good knowledge of different technologies and a couple of languages and maintain the interfaces/code in both worlds - at times is a pain but many times you can achieve very nice results. Have fun.

celavek
  • 5,575
  • 6
  • 41
  • 69
  • thanks for the information. I am going through JNI and i'm trying to implement it. what kind of master/control we have to do? is it riskier to handle in C++ and java interface. My requirement is to add my own property in Preference pages in Java they are using Propertypages package to do that. But how to do it in C++? – Ambuja Jul 26 '11 at 09:17
  • "master/control" - I was referring to the fact that you have to have a good knowledge with different technologies and languages. Why would you need C++ for a Property Page? – celavek Jul 26 '11 at 09:28
  • Cutsomer has asked us to implement it in CDT and also our team do not know Java – Ambuja Jul 26 '11 at 10:05
  • @Ambuja - developing with CDT has nothing to do with Eclipse plugins. – celavek Jul 26 '11 at 11:16
  • @Ambuja - developing with CDT has nothing to do with Eclipse plugins. CDT is the C\C++ toolset which will aloow you to develop C\C++ applications using the Eclipse IDE. The CDT itself is written in Java so that it can be plugged in Eclipse. If you need to develop just a C++ application then you can use Eclipse with CDT as an IDE without worrying about Java. If you need to have a functionality exposed through a C++ app and also through an Eclipse plugin then you go the suggested way: put the functionality into an "engine",then use it from a C++ app and also from an Eclipse plugin via JNI(XPCOM) – celavek Jul 26 '11 at 11:22
  • It is not just c++ application it should be deployable in Eclipse IDE. So, i have to go with the suggested way. Thanks for your suggestion and time. If i get any difficulties while implementing in separate "engine". i'll contact you. Thank you once again. – Ambuja Jul 27 '11 at 08:50
  • celavek, you're confusing java and a jvm. There are plenty of non-java languages that output java bytecode. I'm happily writing Eclipse plugins in jruby, for example. – James Moore Sep 25 '11 at 18:48
  • @James Moore I don't think I'm confusing things. I agree there are non-java languages that output java bytecode - e.g. jython. I never suggested otherwise in the provided answer. – celavek Sep 25 '11 at 21:58
  • No problem, I was just pointing out that "you would have to write your plugin in Java" is misleading - lots of things other than Java produce bytecode that runs on a jvm. – James Moore Sep 26 '11 at 03:31
  • @James Moore noted and acted upon. Thanks – celavek Sep 26 '11 at 07:02
2

I think, this is possible only with use of JNI. So, you'll need Java anyway. Eclipse plugin infrastructure is a pure Java framework.

weekens
  • 8,064
  • 6
  • 45
  • 62
  • thanks for the information. I am going through JNI and will try to implement it. – Ambuja Jul 26 '11 at 09:16
  • Be aware that native part makes your application very unstable. Exception in native part may bring down the whole java machine (i.e. the whole Eclipse). So, maybe, it's better to try Java way? – weekens Jul 26 '11 at 10:41
  • will it be unstable if i use Mozilla XPCOM also? – Ambuja Jul 27 '11 at 08:57