Hi guys, Here are some notes summarising my experience with setting up and running OpenEJB so far. Needless to say that your corrections, additions, criticism and etc are very welcome. Hopefully this quick and dirty walk through will help you to set up and use OpenEJB quickly and easy.
We will start off by going through this little check list and making sure we have everything in place before setting up the OpenEJB container. 1. Make sure you have JDK 5 on your machine and that JAVA_HOME environment variable points to JDK 5. (Note that OpenEJB does not currently work with JDK 6). 2. Make sure you have Maven 2 up and running (This is only required if you are using OpenEJB with Maven, otherwise this item can be ignored). 3. Make sure you have the latest version of OpenEJB (You can get the latest code and building instructions following this link http://openejb.apache.org/source-code.html ) Now we are ready to start playing with OpenEJB. We can use OpenEJB with or without Maven as demonstrated below. But first let us create a tiny sample based on local interface and stateless session bean. Here is the interface: @Local public interface Test { public void test(); } Here is the implementation of the interface: @Stateless public class TestBean implements Test { public void test() { System.out.println("Hello World!"); } } And here is the unit test: public class OpenEJBTestCase extends TestCase { private InitialContext initialContext; protected void setUp() throws Exception { super.setUp(); Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); initialContext = new InitialContext(properties); } public void test() { try { Test test = (Test)initialContext.lookup("TestBeanBusinessLocal"); test.test(); } catch(NamingException exception) { exception.printStackTrace(); } } } Option 1 (Using OpenEJB without Maven 2) 1.Include OpenEJB dependences in your classpath. You can include all jars from the OpenEJB's lib directory for simplicity. 2. Include conf directory in your class path. The conf directory must contain openejb.xml file with the following contents (this essentially tells the container where to find ejb classes for deployment): <?xml version="1.0" encoding="UTF-8"?> <openejb> <Container id="Default CMP Container" ctype="CMP_ENTITY"> </Container> <Deployments dir="bin" /> </openejb> 3. Run the test and check the output, which should read something similar to this: Apache OpenEJB 3.0.0-SNAPSHOT build: 20070823-10:19 http://openejb.apache.org/ OpenEJB ready. Hello World! Option 2 (Using OpenEJB with Maven 2) 1. Update the pom file of your project with the following configuration: <dependency> <groupId>org.apache.openejb</groupId> <artifactId>openejb-core</artifactId> <version>3.0.0-SNAPSHOT</version> <scope>test</scope> </dependency> </dependencies> 2. Include conf directory in your class path. The conf directory must contain the same openejb.xml file as mentioned in the Option 1 above. There are seem to be two ways of doing so. First, you can place the conf directory and the file at the root of your project. In this case the setUp method of your test case will remain the same as mentioned in the Option 1. Second, you can place the conf directory and the file in the src\main\resources directory of your project. In this case the setUp method of your test case needs to be modified as follows: protected void setUp() throws Exception { super.setUp(); Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); properties.setProperty("openejb.configuration", "./target/classes/conf/openejb.xml"); initialContext = new InitialContext(properties); } Note the additional configuration property which tells the container where to find openejb.xml 3. Run the test and check the output. This is where things get confusing (for me anyway). The output will first show a warning saying that ejb-jar.xml cannot be found and after a series of other steps we will see a MelformedURLException message (looks like the container couldnt create autoconfiguration based on our session bean). But then the output will show that the new configuration was eventually created (although it looks like we have 2 containers now) and our test finally passed with the Hello World message being printed out. I suppose I messed something up along the line but cant figure out what exactly without having any docs at hand. Also, there are a number of container types mentioned in the container configuration tutorial, but it would be very helpful to know what they mean and what are the implications of using one or another. I will try to look at how things work with jpa, ejbs, mdbs and etc more closely. Can anyone please point me to the place where I could find more or less up to date info on how they can be configured? Also, I came across admin web console example applicable to OpenEJB 1.0, is there anything similar which could be used with version 3? Cheers Denis -- View this message in context: http://www.nabble.com/Setup-tutorial--tf4337589.html#a12355331 Sent from the OpenEJB User mailing list archive at Nabble.com.