Archive for the 'Eclipse' Category

Nov 20 2012

Three problems with starting brand new Eclipse 4 RCP application

Published by under Eclipse,IT,Java

Recently I decided to finally give Eclipse 4 RCP a try. I created small application in a few minutes. Everything worked smoothly in Eclipse IDE. Next step was to prepare Maven build. Using Tycho 0.16.0 I was able to build my brand new RCP application using command line. The problems started when I tried to run application built by Maven.

Here are three problems I experienced:

  • Application crashing on start-up with an exception like this:
    null argument:applicationXMI argument missing

    In order to resolve that I had to add new program argument (Launching tab in Product Configuration Editor)

  • Application crashing on start-up with another exception:
    !ENTRY org.eclipse.osgi 4 0 2012-11-20 20:43:46.516
    !MESSAGE Application error
    !STACK 1
    java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).

    When you run your RCP application from IDE start-up levels for bundles are set appropriately, but this does not happen in product configuration. These three bundles should have Auto-Start set to true and following start levels (Configuration tab in Editor):

    • org.eclipse.core.runtime 2
    • org.eclipse.equinox.ds 3
    • org.eclipse.equinox.event 3
  • Application starting up fine but no controls being rendered inside a part. Eclipse remote debug helped me to determine that an part object was instantiated as expectged but a method creating all the controls wasn’t actually called. For some reason annotation @PostConstruct wasn’t respected. In order to resolve this issue I had to replace bundle javax.annotation 1.1.0 with version 1.0.0. Eclipse Juno IDE is shipped with version 1.0.0 so everything worked fine there but Tycho picked up version 1.1.0 from Eclipse p2 repository for Juno.

5 responses so far

Jun 01 2010

Generating p2 meta data from command line

Published by under Eclipse,IT,Java

Many times when working with Eclipse RCP I had to generate ad-hoc updatesites (usually containing some 3rd party plug-ins). What I usually did to achieve this (with Eclipse IDE):

  • create new feature project
  • add plug-ins to the feature
  • create new updatesite project
  • add the feature to the updatesite (pre-p2 style – site.xml)
  • export newly created updatesite (letting Eclipse to deal with creating p2 meta data)

Since I needed to automate this process I started researching on p2 capabilities and found out that it can be done from command line using FeatureAndBundlesPublisher application. Sample command line invocation to do it:

%ECLIPSE_EXE% -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher -metadataRepository file:/%P2_TARGET% -artifactRepository file:/%P2_TARGET% -source %P2_SRC% -compress -configs win32.win32.x86 -publishArtifacts


  • ECLIPSE_EXE – points to Eclipse executable;
  • P2_TARGET – path to an empty directory where p2 repository should be created;
  • P2_SRC – path to the directory with /plugins subdirectory and plug-ins to be published (jar files) inside;
  • -compress parameter is optional. It compresses artifacts.xml and content.xml to jar (zip) files.

10 responses so far

Jan 22 2010

Running servlets inside Equinox/Eclipse

Published by under Eclipse,IT,Java

  • Creating plug-in hosting servlet
    • Create new plug-in projectequinox_servlets_1
    • Add plug-in dependencies
      • javax.servlet
      • org.eclipse.equinox.http.registry
    • Add extension: org.eclipse.equinox.http.registry.servlets
    • Configure servlet mapping in extension definition
      <?xml version="1.0" encoding="UTF-8"?>
      <?eclipse version="3.4"?>
      	<extension point="org.eclipse.equinox.http.registry.servlets">
      		<servlet alias="/echo" class="servlets.EchoServlet" />
    • Create servlet class
      package servlets;
      package servlets;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      public class EchoServlet extends HttpServlet {
      	private static final long serialVersionUID = 137926368689939745L;
      	protected void doGet(HttpServletRequest request,
      			HttpServletResponse response) {
      		String value = request.getParameter("value");
      		PrintWriter writer;
      		try {
      			writer = response.getWriter();
      			String outputText = "Echo Servlet inside Equinox/Eclipse says: "
      					+ value;
      		} catch (IOException e) {
      			// TODO Auto-generated catch block
  • Running plug-in hosting servlets in Eclipse IDE
    • Create new Run Configuration
    • Choose OSGi Framework
    • Deselect all preselected plug-ins from bundles list
    • Select only:
      • Newly created plug-in that’s hosting servlets
      • org.mortbay.jetty.server
      • org.eclipse.equinox.http.jetty
    • Use Add Required Bundles option
    • Save configuration and Run it
  • Using servlet
    • By default when running this configuration Jetty will start on port 80
    • Open a browser and hit URL for this example http://localhost/echo?value=Helloequinox_servlets_2equinox_servlets_3

3 responses so far

Oct 27 2009

Adding menu item, command and handler

Published by under Eclipse,IT,Java

Step by step in Eclipse IDE

  • Create new Eclipse plug-in: File -> New -> Other -> Plug-in Development -> Plug-in Project
  • Add dependency: MANIFEST.MF -> Dependencies tab -> Add -> org.eclipse.ui
  • Add extension point org.eclipse.ui.menus: plugin.xml -> Extension -> Add -> org.eclipse.ui.menus
    • Right-click -> New -> menuContribution
      • Enter locationURI: menu:file
        • Right click -> New -> command
        • Enter commandId: tk.urbas.eclipse.sample.sampleCommand
        • Enter label: Sample Menu Item
  • Add extension point org.eclipse.ui.commands: plugin.xml -> Extensions -> Add -> org.eclipse.ui.commands
    • Right-click -> New -> command
      • Enter id: tk.urbas.eclipse.sample.sampleCommand
      • Enter label: Sample Command
  • Add extension point org.eclipse.ui.handlers: plugin.xml -> Extensions -> Add -> org.eclipse.ui.handlers
    • Right-click -> New -> handler
      • Enter commandId: tk.urbas.eclipse.sample.sampleCommand
      • Enter class: tk.urbas.eclipse.sample.SampleHandler
      • Click class link and create class
      • Provide sample implementation of the handler class implementing org.eclipse.core.commands.IHandler or extending org.eclipse.core.commands.AbstractHandler

Menu, command, handler

Menu, command, handler


Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Sample Handler
Bundle-SymbolicName: tk.urbas.eclipse.sample;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.ui


<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
               label="Sample Menu Item"
            name="Sample Command">

Handler – sample implementation showing a message

package tk.urbas.eclipse.sample;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
public class SampleHandler extends AbstractHandler {
	public Object execute(ExecutionEvent event) throws ExecutionException {
				"Sample Handler", "Sample Handler");
		return null;

2 responses so far

Jul 30 2009

Eclipse 3.5 Galileo – my personal Top 5

Published by under Eclipse,IT,Java

There are several new and exciting features in Galileo release. Multiple projects, hundreds of contributors, huge audience…

I decided to choose my very personal Top 5 for Galileo release:

  1. Update. New UI for installing and updating new features in Eclipse really leverages user experience. After introducing p2 in 3.4 a lot of people missed old Update Manager. With more stable and matured p2 in 3.5 version hopefully no one is missing 3.3 style updates any more. One capability I would find useful there is installing particular Installable Units instead just these which are based on Eclipse features. In p2 world all IUs are supposed to be equal.
  2. Setting the cookies in Browser. I’m really happy to finally see setCookie(value, url) method in SWT Browser class. That’s the part of API that was really missing there to make embedded browser more functional in Eclipse RCP world. Next step would be probably providing SWT support for the Webkit based browsers.
  3. Target Platforms. Galileo way of defining target platform is another item I find really useful for Eclipse RCP. Finally at least partially runtime for Eclipse RCP application can be independent from the plug-ins set in Eclipse IDE used for development!
  4. Mylyn. Previous Mylyn version satisfied most of my requirements to work with Bugzilla. But new Mylyn Editor just feels better for me even if it took me a day or two to get used to the context activation button being moved from right to left side of the toolbar.
  5. OSGi Declarative Services. I’m excited about declarative services in Equinox. I didn’t have opportunity to try it yet but I have high hopes for the near future!

2 responses so far

May 18 2009

p2 and fragments

Published by under Eclipse,IT,Java

Recently I’m getting a bit confused about p2. There is an update site created with PDE headless build. There are IUs generated for each plug-in/fragment/feature. Everything looks great so far.

Let’s assume: plug-in A and fragment B with a defined host plug-in A are sitting together on single update site. Plug-in A in reality cannot run without appropriate version of fragment B (e.g. situation similar to SWT).

My understanding of p2-power was that I wouldn’t need to create separate feature C aggregating A and B just to make fragment B be automatically installed when I request installation of plug-in A.

I spent some time on reviewing Eclipse Bugzilla and mailing lists. Interesting findings:

Any suggestions about handling such “required” fragment scenario without getting rid of autogenerated p2 repository and hand crafting p2 metadata?

2 responses so far

Mar 01 2009

Defining a background Job to run periodically

Published by under Eclipse,IT,Java

One may need to run some task periodically in the background in Eclipse. This background task should run automatically and shouldn’t block user from regular usage of the application. My proposal for accomplishing this is using Eclipse Jobs API and org.eclipse.ui.startup extension-point.

  1. Adding org.eclipse.ui.startup extension:
    • Dependencies:
      • org.eclipse.ui
      • org.eclipse.core.runtime
    • Extension:
      <?xml version="1.0" encoding="UTF-8"?>
      <?eclipse version="3.2"?>
         <extension point="org.eclipse.ui.startup">
            <startup class="tk.urbas.eclipse.urbanlife.Startup"></startup>
  2. Implementing Job:
    package tk.urbas.eclipse.urbanlife;
    import org.eclipse.core.runtime.IProgressMonitor;
    import org.eclipse.core.runtime.IStatus;
    import org.eclipse.core.runtime.Status;
    public class RefreshDataJob extends Job {
        public RefreshDataJob(String name) {
        protected IStatus run(IProgressMonitor monitor) {
            // Work to do in the background
            return Status.OK_STATUS;
  3. Scheduling Job to run periodically:
    package tk.urbas.eclipse.urbanlife;
    import org.eclipse.ui.IStartup;
    public class Startup implements IStartup {
        private static final long STARTUP_DELAY = 5000; // 5 seconds delay for first run
        protected static final long JOB_INTERVAL = 60000; // Job should run every 60 seconds
        public void earlyStartup() {
            final Job updateJob = new RefreshDataJob("Refreshing data in the background");
            updateJob.addJobChangeListener(new JobChangeAdapter() {
                public void done(IJobChangeEvent event) {

Let me know if you have any better solution for implementing this. All improvements, suggestions and comments will be greatly appreciated.

10 responses so far

Feb 20 2009

Eclipse plug-in as a web service client

Published by under Eclipse,IT,Java

Recently I was playing around consuming web service inside Eclipse plug-in. Making simple web service call maybe a bit tricky at the beginning. I’m going to provide quick start instruction here,

Required software:

  • Eclipse for RCP/Plug-in Developer
  • JEE Standard Tools & Axis
    JEE Standard Tools

Configuration steps:

  • Define new JEE service in a workspace
    Defining JEE server
  • Create new plug-in project
    Creating new plug-in project
  • Add following dependencies to the plug-in:
    • org.apache.commons.logging
    • javax.wsdl
    • javax.xml.rpc
    • javax.xml.soap
    • org.apache.commons.discovery
    • org.apache.axis

    Web service client dependencies

  • Generate web service client code
    Generating web service client code

    Generating web service client code based on WSDL

Consume web service:

Using web service in side a plug-in is no different than anyone else. Sample of invoking web service method:

TransportServiceSoap service = new TransportServiceLocator().getTransportServiceSoap();

Instruction presented above is based on Eclipse 3.4.1 and uses sample web service from

8 responses so far

Feb 11 2009

Automatic PDE build with Pluginbuilder

Published by under Eclipse

Pluginbuilder is Eclipse tool that generates build configuration based on PDE build. By default the tool generates map file containing the information how source code of the plug-ins should be obtained. Supported methods are: CVS, GET and COPY. Assuming that you want to build your features or product from source files that are checked-out from repository independently from the build process COPY options seems to look reasonable. There are few problems with that:

  • it requires absolute paths to plug-ins/features locations
  • every single plug-in has to be listed there

Workaround for this is not using map file at all and provide appropriate build directory structure outside. To skip fetching resources based on map file configuration one need to set skipMaps property in file. Next step is to configure getting plug-ins/features resources into build directory. Recommended phase for copying the source code is preSetup phase in PDE build. To hook into this phase standard ant task for copying the files/directories in to build directory have to be invoked in preSetup target in customTargets.xml (it is generated by Pluginbuilder as well as other configuratoin files in build-files directory).

Those two modifications allow to make use of Pluginbuilder generated scripts to build Eclipse based applications without coupling it tightly to version control system.

One response so far

Feb 04 2009

Eclipse Jobs API – Errata

Published by under Eclipse,IT,Java

My colleague Lukasz Milewski has just spotted a missing piece in a code sample for creating icons presented in previous post. In the screenshot you can see nice icons for currently running Jobs as well as for scheduled Jobs. You need to set two properties in your Job implementation to associate an icon with it.

	setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
	setProperty(IProgressConstants.ICON_PROPERTY, ImageDescriptorFactory

4 responses so far

Next »