Some code to test

To get something working we need to insert some code in our RCP. We will insert it directly in the Application.java. All output will be echo to the console so that there is no need for a GUI:

Application.java

JAVA:
  1. package bz.jmc.blog.rcp_with_jboss.rcp;
  2.  
  3. import java.util.Properties;
  4.  
  5. import javax.naming.Context;
  6. import javax.naming.InitialContext;
  7.  
  8. import org.eclipse.core.runtime.IPlatformRunnable;
  9. import org.eclipse.swt.widgets.Display;
  10. import org.eclipse.ui.PlatformUI;
  11.  
  12. import bz.jmc.blog.tutorial.rcp_with_jboss.ejb.MyTestStatelessSessionRemote;
  13.  
  14. /**
  15. * This class controls all aspects of the application's execution
  16. */
  17. public class Application implements IPlatformRunnable {
  18.  
  19. /* (non-Javadoc)
  20. * @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object)
  21. */
  22. public Object run(Object args) throws Exception {
  23. // EJB-Test
  24. //
  25. Properties properties = new Properties();
  26. properties.put("java.naming.factory.initial",
  27. "org.jnp.interfaces.NamingContextFactory");
  28. properties.put("java.naming.factory.url.pkgs",
  29. "=org.jboss.naming:org.jnp.interfaces");
  30. properties.put("java.naming.provider.url","localhost:1099");
  31.  
  32. Context context;
  33. try {
  34. context = new InitialContext(properties);
  35. MyTestStatelessSessionRemote sess =
  36. (MyTestStatelessSessionRemote)
  37. context.lookup("MyTestStatelessSessionBean/remote");
  38. System.out.println( sess.sayHello() );
  39. } catch (Exception e) {
  40. e.printStackTrace();
  41. }
  42. // Normal RCP-App Code
  43. Display display = PlatformUI.createDisplay();
  44. try {
  45. int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
  46. if (returnCode == PlatformUI.RETURN_RESTART) {
  47. return IPlatformRunnable.EXIT_RESTART;
  48. }
  49. return IPlatformRunnable.EXIT_OK;
  50. } finally {
  51. display.dispose();
  52. }
  53. }
  54. }

Now click on "Lauch an Eclipse application" in the "Overview"-tab to lauch the RCP. If anything is OK you should see a RCP window and an output similar to this one:

Erfolgreicher Test der RCP

Hopefully this small tutorial is a little helpful.

Start Slide Show with Cooliris