A few days ago I got involved in the development of a new OpenGL plug-in for Eclipse: Eclipse OpenGL Pack.
My first task is to create some window where the OpenGL capabilities of the current system are shown. Something similar to what NetBeans OpenGL pack does (i.e. this screenshot).
One of the features that I like about the plug-in is that new OpenGL bindings can be added (through extensions points), so there’s no only one binding like NetBeans OpenGL pack.
Unfortunately, at the same time this feature means some more “headaches” for developing the plug-in. It means that we don’t know what library the developer will choose to use OpenGL.
We decided that an option, in order to retrieve the OpenGL characteristics of the system, is to run a small Java program inside the plug-in with one of the OpenGL bindings (selected by user) to ask for extensions, capabilities, maximum values and similar things.
It sounds easy: run a java program inside the plug-in. I started to investigate in the Plug-in Developer Guide in the Eclipse Help, I ended up in the Launching Program topic… My first impression wasn’t good, so I searched deeply and a good candidate was the topic Launching Java Application (actually that was exactly what I wanted) where I found what look like an article about Launching Java Applications Programmatically with examples about how doing such task.
After some hours spent trying to figure out how it works and how it should be used, finally I got some code that did what I wanted: run an small program (included in the plug-in) with custom classpath (It took a while to find how to retrieve the classpath to use the current plug-in classes) without leaving traces to the Eclipse Running history (IDebugUIConstants.ATTR_PRIVATE).
One of the problems about deciding to launch a Java Program was how to capture the OpenGL information that it’s going to retrieve in order to show it in the plug-in window. I decided that the first thing that I’m going to try is to print such information in the standard output.
So I needed to capture the output using some of the classes used in the article.
Continue reading “Launching a Java program inside an Eclipse plug-in (and capture its output)”
