JMCblog

Nothing in particular…

Archiv der ‘JBoss’ Kategorie

Mittwoch
Sep 26,2007

Gerhard Schuster is working on some How-to’s about how to use Eclipse 3.3 to develop and connect EJB 3.0 Beans running on JBoss 4.2.

He’s using a lot of screenshots to make it easy to follow his instructions.

I think it is a worthwhile read for anybody interested in this topic who wants some more detail than my article can offer.

You can find Gerhards articles here:

Connect JBoss and Eclipse

Learn how to deploy a bean to JBoss using Eclipse

Sonntag
Mai 20,2007

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
Sonntag
Mai 20,2007

Dependencies und Buddy-Policy

First we need to declare the RCP dependend on the JBoss-plugin.

Declaring dependency

Now we define the Buddy-Policy in the JBoss plugin ( insert "Eclipse-BuddyPolicy: registered" in the Manifest.MF) and let the RCP-Plugin register as a buddy (insert "Eclipse-RegisterBuddy: org.jboss.client" in the Manifest.MF). Please ensure that there is always a blank line at the end of the Manifest.MF and there is no whitespace in front of the "Eclipse-..."!

Buddy-Policy festlegen
Buddy-Policy festlegen

Insert the EJB-Classes in our RCP-Plugin

We need to let our plugin know the EJBs it should work with. Inside the project we create a new folder called "libs" and copy the file MyTestStatelessSession.jar into it. Now we will refresh the project and add the JAR to the build path by right-clicking on the file and choose Build Path > Add to Build Path. The result should look like this:

Adding EJB-Classes

As a last step we need to add the EJB-Jar to the classpath under Runtime. Without this step our JBoss-Plugin is not able to find the classes at runtime.

EJB-Jar dem Classpath hinzufügen

In the last part I will show you how to create some test code to ensure anything is working.

Start Slide Show with Cooliris
Sonntag
Mai 20,2007

Creating the RCP-Plugins

Using the menus File > New > Project we will create our RCP. All details you can find in the following 4 screenshots:

RCP Plugin Projekt anlegen
RCP Plugin Projekt anlegen
RCP Plugin Projekt anlegen
RCP Plugin Projekt anlegen

Creating the JBoss-Client-Plugin

Our plugin with the JBoss-Classes will be created similar to the RCP-plugin. But in this case we are using "Plug-in from existing JAR archives".

Create JBoss-Client-Plugin

In the next dialog we are choosing Add external and select all JARs in the %JBOSSHOME%/client folder. The auth.conf file should not be selected!

Create JBoss-Client-Plugin
Create JBoss-Client-Plugin

Now we need to define the dependency between the two plugins and create a Buddy-Policy. I'll show that to you in part 4.

Start Slide Show with Cooliris
Sonntag
Mai 20,2007

The Demo-EJB

As a simple example EJB, which will be used in our RCP, we will use a small EJB 3.0 stateless session bean. It's a typical "Hello World" bean:

MyTestStatelessSessionRemote.java

JAVA:
  1. package bz.jmc.blog.tutorial.rcp_with_jboss.ejb;
  2.  
  3. import javax.ejb.Remote;
  4.  
  5. public interface MyTestStatelessSessionRemote {
  6.  
  7. public String sayHello();
  8.  
  9. }

MyTestStatelessSessionBean.java

JAVA:
  1. package bz.jmc.blog.tutorial.rcp_with_jboss.ejb;
  2.  
  3. import javax.ejb.Stateless;
  4.  
  5. @Stateless
  6. public class MyTestStatelessSessionBean implements MyTestStatelessSessionRemote {
  7.  
  8. public String sayHello() {
  9. return "Hello World! I'm an Stateless-Session-Bean";
  10. }
  11.  
  12. }

This Bean will be packaged in a JAR-file called MyTestStatelessSession.jar and needs to be deployed to JBoss. After deployment JBoss should echo something like this:

CODE:
  1. 11:31:25,651 INFO  [Server] JBoss (MX MicroKernel) [4.0.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)] Started in 1m:21s:287ms
  2. 11:39:01,958 INFO  [Ejb3Deployment] EJB3 deployment time took: 88
  3. 11:39:02,027 INFO  [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=MyTestStatelessSession.jar, name=MyTestStatelessSessionBean, service=EJB3 with dependencies:
  4. 11:39:03,276 INFO  [EJBContainer] STARTED EJB: bz.jmc.blog.tutorial.rcp_with_jboss.ejb.MyTestStatelessSessionBean ejbName: MyTestStatelessSessionBean
  5. 11:39:03,697 INFO  [EJB3Deployer] Deployed: file:/Users/jmc/Applications/jboss-4.0.4.GA/server/default/deploy/MyTestStatelessSession.jar

In the next part I'll show you how to create our simple RCP application.


JMC on flickr

Protected mannequinsGeflügelter TelemichelLomo Action ShooterNeela - That's my toy!

Letzte Kommentare


Schlagwörter

Apple assignments aufgaben aufgaben assignments b&w black classic d300 day88 dia dockland fehmarn film Flickr Hörertreffen hamburg HappyShooting Holga hund iPhone ipod itunes Kopenhagen live microsoft mittelformat musik Nikon p6000 photo assignment aufgabe Photographie Project365 project365 photofriday raw review schwarz shuffle Strobist VFXY view weiß white wic Wordpress Workshop

VFXY Photos 2008 Photoblog Awards