Using JBoss EJB 3 with Eclipse RCP [Part 5]

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]
package bz.jmc.blog.rcp_with_jboss.rcp;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import org.eclipse.core.runtime.IPlatformRunnable;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

import bz.jmc.blog.tutorial.rcp_with_jboss.ejb.MyTestStatelessSessionRemote;

/**
* This class controls all aspects of the application’s execution
*/
public class Application implements IPlatformRunnable {

/* (non-Javadoc)
* @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object)
*/
public Object run(Object args) throws Exception {
// EJB-Test
//
Properties properties = new Properties();
properties.put(„java.naming.factory.initial“,
„org.jnp.interfaces.NamingContextFactory“);
properties.put(„java.naming.factory.url.pkgs“,
„=org.jboss.naming:org.jnp.interfaces“);
properties.put(„java.naming.provider.url“,“localhost:1099″);

Context context;
try {
context = new InitialContext(properties);
MyTestStatelessSessionRemote sess =
(MyTestStatelessSessionRemote)
context.lookup(„MyTestStatelessSessionBean/remote“);
System.out.println( sess.sayHello() );
} catch (Exception e) {
e.printStackTrace();
}
// Normal RCP-App Code
Display display = PlatformUI.createDisplay();
try {
int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART) {
return IPlatformRunnable.EXIT_RESTART;
}
return IPlatformRunnable.EXIT_OK;
} finally {
display.dispose();
}
}
}
[/java]

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.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *