You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

When your clients run OpenEJB in the same VM using the IntraVM Server, you're using OpenEJB as an embedded EJB Server just like InstantDB and Cloudscape are embedded databases servers. Just like InstantDB and Cloudscape, OpenEJB needs configuration files and other files to do it's job.

When accessing OpenEJB in local (intra-vm) mode, the IntraVM server will instantiate OpenEJB for you. When it instantiates OpenEJB, it puts default values for the items in the Properties object OpenEJB needs to actually instantiate.

No place like home

Passing initialization parameters

When accessing OpenEJB in local (intra-vm) mode, the IntraVM server will instantiate OpenEJB for you. When it instantiates OpenEJB, it puts default values for the items in the Properties object OpenEJB needs to actually instantiate.

If you want to pass OpenEJB specific parameters, you can do this in two ways:
Call init yourself before any JNDI calls are made
Pass the parameters in the InitialContext hashtable

Refer to the OpenEJB Specification for information on the init method or the parameters you can pass to OpenEJB.

Here is an example of passing the initialization parameters in to OpenEJB via the first InitialContext creation. I stress, this is only applicable the very first time and InitialContext is created within your Virtual Machine. After that, OpenEJB will have been initialized and the parameters will be ignored.

MyEjbApplication.java
import FooHome;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class MyEjbApplication {

public static void main( String args[]) {
  try{
    
    Properties p = new Properties();
    
    p.put(Context.INITIAL_CONTEXT_FACTORY, 
          "org.openejb.client.LocalInitialContextFactory");
    
    p.put("openejb.home", "c:\\dir\\openejb");
    
    p.put("openejb.configuration", 
          "c:\\my\\app\\conf\\openejb.conf");
    
    InitialContext ctx = new InitialContext( p );
    
    Object obj = ctx.lookup("my/bean/Foo");
    
    FooHome ejbHome = (FooHome)
        PortableRemoteObject.narrow(obj,FooHome.class);
  
  } catch (Exception e){
    e.printStackTRace();
  }
}
}

Set the openejb.home variable

If you use OpenEJB Local Server, you are actually using OpenEJB as an embedded library. This means when your application starts, OpenEJB will be starting too, in your virtual machine. Odds are you will not want to execute your application in the directory where OpenEJB was installed, but will want to execute your application where you are developing it. This is fine, but you will need to tell OpenEJB where it was installed. To do this, set the "openejb.home" system variable.

For example, if OpenEJB was unpacked in the directory in c:\dir\openejb, you can set the openejb.home variable as a java vm flag as follows.

c:\my\app> java -Dopenejb.home=c:\dir\openejb MyEjbApplication

You can also set the openejb.home variable by calling System.setProperty(...) in your application before any calls to the OpenEJB Local Server are made.

MyEjbApplication.java
...
public static void main(String args[]) {
    
  System.setProperty("openejb.home", "c:\\dir\\openejb");
  ...
  
}
...

As mentioned above, you can pass OpenEJB parameters on your first call to the Local Server.

MyEjbApplication.java
...
public static void main( String args[]) {
    
  Properties p = new Properties();
  
  p.put(Context.INITIAL_CONTEXT_FACTORY, 
        "org.openejb.client.LocalInitialContextFactory");
  
  p.put("openejb.home", "c:\\dir\\openejb");
      
  InitialContext ctx = new InitialContext( p );
  ...
}
...

When OpenEJB is started, it will look for its configuration files in the OPENJB_HOME/conf directory. The paths to beans in your openejb.conf file are also resolved relative to the openejb.home variable.

Using openejb.conf files

Here is an example of this. The openejb.home variable, which we will refer to as OPENEJB_HOME, is set to "c:\dir\openejb". The following relative path in your openejb.conf file will be resolved assuming OPENEJB_HOME as the base path.

openejb.conf
<openejb>
...

<Deployments dir="beans\" />
</openejb>

The above deployment path, "beans\", would automatically be expanded to "c:\dir\openejb\beans".

If you want tell OpenEJB to look outside the OPENEJB_HOME, then use an absolute file path as shown below.

openejb.conf
<openejb>
...

<Deployments dir="beans\" />
<Deployments dir="c:\my\app\my\beans\" />
</openejb>

OpenEJB can look in any number of directories for beans, just add those directories to your openejb.conf file as such.

openejb.conf
<openejb>
...

<Deployments dir="beans\" />
<Deployments dir="c:\my\app\my\beans\" />
<Deployments dir="c:\my\special\beans\" />
<Deployments dir="c:\foo\ejbs\" />
<Deployments dir="d:\files\ejbjars\" />
</openejb>

Furthermore, you can add jars individually to OpenEJB's deployment path by naming the jar directly.

openejb.conf
<openejb>
...

<Deployments dir="beans\" />
<Deployments dir="c:\my\app\my\beans\" />
<Deployments dir="c:\my\special\beans\" />
<Deployments dir="c:\foo\ejbs\" />
<Deployments dir="d:\files\ejbjars\" />
<Deployments jar="c:\the\very\special.jar" />
</openejb>
  • No labels