Jan 14 2009

Launching a Java program inside an Eclipse plug-in (and capture its output)

Category: Eclipse OpenGL Pack, Pluginsramon @ 9:43 am

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)”

pixelstats trackingpixel


Nov 20 2008

Eclipse SWT doesn’t run in Java 1.6? (Mac OS X)

Category: Eclipse, Javaramon @ 8:49 am

I’ve just downloaded the last Eclipse 3.4.1 for Mac OS X and went through the “Simple plug-in example” to try to get a picture about how to develop plug-ins for pictures.

Basically the problem was when I tried to start the plug-in that I got an error. Basically in the error log there’s something like:

java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM

The error is quite clear, it seems that SWT libraries are 32 bits and my environment is 64 JVM. As I’m just a newbie with Leopard I don’t really know how to check if the java version that I’ve in the system is 32 or 64 bits as the java -version doesn’t say anything about that.

I tried to run the java 1.6 that’s also in the system, then the output for java version it was like that:
/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java -version

java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06-153)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-57, mixed mode)

The “64-Bit Server VM” makes it clear. That made me wonder what JVM is Eclipse using, first I checked the project properties and the Java Compiler was set to 1.5 level. But still the problem was there.

Later on I remembered that Eclipse uses your preferred JVM to run your programs independently of whatever compliance level is set in the project (or Eclipse). So the key to solve that issue is to change your default JVM in the Eclipse preferences under the “Installed JREs” to point to JVM 1.5.0.

If 1.5.0 is the default in the Mac OS X system why Eclipse did choose 1.6 as the default one?

pixelstats trackingpixel

Tags: , , , ,