Move to Wordpress

I decided to drop my own hosting and moved to WordPress hosting. Since 2007 this blog was hosted at http://urbas.tk but recently it was moved to https://radektech.wordpress.com.

Advertisements

Three problems with starting brand new Eclipse 4 RCP application

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.

Running servlets inside Equinox/Eclipse

  • 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

Adding menu item, command and handler

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;
	}
}

JDD09

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:

Eclipse 3.5 Galileo – my personal Top 5

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!