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:
    org.eclipse.core.runtime.AssertionFailedException:
    null argument:applicationXMI argument missing

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

    -clearPersistedState
  • 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.

3 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

Where:

  • 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.

9 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"?>
      <plugin>
       
      	<extension point="org.eclipse.equinox.http.registry.servlets">
      		<servlet alias="/echo" class="servlets.EchoServlet" />
      	</extension>
       
      </plugin>
    • Create servlet class
      package servlets;
       
      package servlets;
       
      import java.io.IOException;
      import java.io.PrintWriter;
       
      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;
       
      	@Override
      	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;
      			System.out.println(outputText);
      			writer.write(outputText);
      			writer.close();
      		} catch (IOException e) {
      			// TODO Auto-generated catch block
      			e.printStackTrace();
      		}
       
      	}
      }
  • 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.MF

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-Vendor: urbas.tk
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.ui

plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:file">
         <command
               commandId="tk.urbas.eclipse.sample.sampleCommand"
               label="Sample Menu Item"
               style="push">
         </command>
      </menuContribution>
   </extension>
   <extension
         point="org.eclipse.ui.commands">
      <command
            id="tk.urbas.eclipse.sample.sampleCommand"
            name="Sample Command">
      </command>
   </extension>
   <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="tk.urbas.eclipse.sample.SampleHandler"
            commandId="tk.urbas.eclipse.sample.sampleCommand">
      </handler>
   </extension>
 
</plugin>

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 {
 
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		MessageDialog.openInformation(Display.getDefault().getActiveShell(),
				"Sample Handler", "Sample Handler");
		return null;
	}
}

2 responses so far

Oct 17 2009

JDD09

Published by under IT,Java

Java Developers' Day4th edition of Java Developers’ Day is over. It was the first time I attended this conference. I enjoyed most of the sessions and the organization was pretty good. I will definitely plan to be there next year as well. My favorite JDD09 speakers/sessions:

No responses yet

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

Jul 21 2009

Considering learning new language/technology

Published by under General,IT

I’m considering learning new programming language or technology.

My very basic requirements:

  • no for buying new laptop (I’m happy with my ThinkPad)
  • no for buying new mobile device just to run something at all (I’m happy with my Nokia)

Any suggestions?

One response so far

Jun 20 2009

That is why WordPress is so cool

Published by under General

Single click …

Downloading update from http://wordpress.org/wordpress-2.8.zip
Unpacking the core update
Verifying the unpacked files
Installing the latest version
Upgrading database

WordPress upgraded successfully

… and voilà! Upgrade completed!

2 responses so far

Jun 08 2009

June 2009 elections at the European Parliament

Published by under General

The website of Państwowa Komisja Wyborcza (the institution responsible for the elections in Poland) around the time when the official results are supposed to be published.

Państwowa Komisja Wyborcza

Państwowa Komisja Wyborcza

No responses yet

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:

http://wiki.eclipse.org/Equinox_p2_Meeting_2007#Fragments_optional_vs._requirement

https://bugs.eclipse.org/bugs/show_bug.cgi?id=256430

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

2 responses so far

Next »