Note | ||
---|---|---|
| ||
Restrictions |
Install Tomcat 6
If you already have Tomcat 6 installed, skip to Install OpenEJB.
Unpack Tomcat
Unpack the Tomcat zip file which will create a new directory containing the complete Tomcat installation.
Code Block | ||||
---|---|---|---|---|
| ||||
$ jar -xvf | ||||
Wiki Markup | ||||
h1. Install Tomcat 6 If you already have Tomcat 6 installed, skip to [Install OpenEJB|#install-openejb]. h2. Unpack Tomcat Unpack the Tomcat zip file which will create a new directory containing the complete Tomcat installation. {code:none}$ jar -xvf apache-tomcat-6.0.14.zip created: apache-tomcat-6.0.14/ created: apache-tomcat-6.0.14/bin/ created: apache-tomcat-6.0.14/conf/ ...snip... {code} Change to the new Tomcat installation directory. {code:none}$ cd apache-tomcat-6.0.14/{code} The Tomcat installation should contain the following files: {code:none}apache-tomcat-6.0.14.14$zip ls LICENSE RELEASE-NOTES bin/ lib/ temp/ work/ NOTICE RUNNING.txt conf/ created: apache-tomcat-6.0.14/ created: apache-tomcat-6.0.14/bin/ created: apache-tomcat-6.0.14/conf/ ...snip... |
Change to the new Tomcat installation directory.
Code Block | ||||
---|---|---|---|---|
| ||||
$ cd apache-tomcat-6.0.14/ |
The Tomcat installation should contain the following files:
Code Block | ||||
---|---|---|---|---|
| ||||
apache-tomcat-6.0.14$ ls LICENSE logs/ RELEASE-NOTES bin/ webapps/ {code} h2. Make shell scripts executable The shell scripts in the Tomcat installation are not executable by default, so in order to execute them, you must set mark them as executable. If you unpacked the Tomcat tar.gz file, the scripts are already executable. The following command will make all shell scripts executable: {code}apache-tomcat-6.0.14$ chmod u+x bin/*.sh{code} h2. Start Tomcat Execute the following command to start the Tomcat server to verify it is functioning properly: {code:none}apache-tomcat-6.0.14$ bin/startup.sh Using CATALINA_BASE: /your/tomcat/installation/ lib/ temp/ work/ NOTICE RUNNING.txt conf/ logs/ webapps/ |
Make shell scripts executable
The shell scripts in the Tomcat installation are not executable by default, so in order to execute them, you must set mark them as executable. If you unpacked the Tomcat tar.gz file, the scripts are already executable. The following command will make all shell scripts executable:
Code Block |
---|
apache-tomcat-6.0.14 Using CATALINA_HOME: /your/tomcat/installation/apache-tomcat-6.0.1414$ chmod u+x bin/*.sh |
Start Tomcat
Execute the following command to start the Tomcat server to verify it is functioning properly:
Code Block | ||||
---|---|---|---|---|
| ||||
apache-tomcat-6.0.14$ bin/startup.sh Using CATALINA_BASE: Using CATALINA_TMPDIR: /your/tomcat/installation/apache-tomcat-6.0.14/temp Using JRECATALINA_HOME: /your/javatomcat/installation{code} *NOTE:* Your output will be different from the example above due to differences in installation location. h2. Verify Tomcat is Running Visit [/apache-tomcat-6.0.14 Using CATALINA_TMPDIR: /your/tomcat/installation/apache-tomcat-6.0.14/temp Using JRE_HOME: /your/java/installation |
NOTE: Your output will be different from the example above due to differences in installation location.
Verify Tomcat is Running
Visit http://localhost:8080/
...
and
...
you
...
should
...
see
...
the
...
Tomcat
...
welcome
...
page.
Stop Tomcat
Shutdown Tomcat by executing the following command:
Code Block | ||||
---|---|---|---|---|
| ||||
h2. Stop Tomcat Shutdown Tomcat by executing the following command: {code:none}apache-tomcat-6.0.14$ bin/shutdown.sh Using CATALINA_BASE: /your/tomcat/installation/apache-tomcat-6.0.14 Using CATALINA_HOME: /your/tomcat/installation/apache-tomcat-6.0.14 Using CATALINA_TMPDIR: /your/tomcat/installation/apache-tomcat-6.0.14/temp Using JRE_HOME: /your/java/installation{code} * |
NOTE:
...
Your
...
output
...
will
...
be
...
different
...
from
...
the
...
example
...
above
...
due
...
to
...
differences
...
in
...
installation
...
location.
...
Anchor | ||||
---|---|---|---|---|
|
...
...
OpenEJB
...
Once
...
Tomcat
...
has
...
been
...
installed,
...
the
...
OpenEJB
...
plugin
...
for
...
Tomcat
...
can
...
be
...
installed.
...
The
...
commands
...
in
...
this
...
example
...
are
...
executed
...
within
...
the
...
Tomcat
...
installation
...
directory.
...
Unpack
...
OpenEJB
...
Tomcat
...
plugin
...
in
...
Tomcat
...
webapps
...
directory
...
1. Change
...
to
...
the
...
webapps
...
directory:
Code Block | |||||
---|---|---|---|---|---|
| |||||
}apache-tomcat-6.0.14$ cd webapps{code} Unpack the |
2. Unpack the openejb-tomcat-3.0.0-SNAPSHOT-bin.zip
...
file.
Code Block | ||||
---|---|---|---|---|
| ||||
{code:none}apache-tomcat-6.0.14/webapps$ jar -xvf ../openejb-tomcat-3.0.0-SNAPSHOT-bin.zip
created: openejb/
created: openejb/WEB-INF/
created: openejb/lib/
inflated: openejb/lib/geronimo-javamail_1.4_spec-1.1.jar
inflated: openejb/lib/xbean-finder-3.1.jar
...snip...
|
3. The OpenEJB directory should contain the following files:
Code Block | ||||
---|---|---|---|---|
| ||||
{code} The OpenEJB directory should contain the following files: {code:none}apache-tomcat-6.0.14/webapps$ ls openejb WEB-INF/ lib/ openejb.xml {code} Return to the Tomcat install directory {code:none}apache-tomcat-6.0.14/webapps$ cd ..{code} h2. Add the OpenEJB listener to Tomcat Tomcat listeners must be available in the Tomcat common class loader, |
4. Start tomcat again
5. Visit http://localhost:8080/openejb/installer and click on the install button
6. Assuming you don't get any errors, reboot tomcat
At this point OpenEJB will be installed
Info | ||
---|---|---|
| ||
|
Test an example application
Create a stateless session bean
Create an interface
Code Block | ||||
---|---|---|---|---|
| ||||
package org.acme;
import javax.ejb.*;
@Remote
public interface Greeting{
public String greet();
}
|
Create the bean class
Code Block | ||||
---|---|---|---|---|
| ||||
package org.acme;
import javax.ejb.*;
@Stateless
public class GreetingBean implements Greeting{
public String greet(){
return "I just greeted you buddy";
}
}
|
Create a servlet
Code Block | ||||
---|---|---|---|---|
| ||||
package org.acme;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import java.io.*;
import java.util.*;
public class TestServlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response){
try{
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
Properties p = new Properties();
p.put("java.naming.factory.initial","org.apache.openejb.client.LocalInitialContextFactory");
InitialContext ctx = new InitialContext(p);
Greeting g = (Greeting)ctx.lookup("GreetingBeanBusinessRemote");
writer.print(g.greet());
}catch(Exception e){
e.printStackTrace();
}
}
}
|
Register the servlet in web.xml
Code Block | ||||
---|---|---|---|---|
| ||||
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Test Application</display-name>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>org.acme.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
</web-app>
|
Package the war
Compile the above classes into the WEB-INF/classes directory and package everything into testweb.war (or a file name of your liking)
Drop the war in the tomcat webapps directory
Drop the testweb.war in the tomcat webapps directory
Send a request to the servlet
#Open the browser
#Send a request to http://localhost:8080/testweb/test
#You should now see the message "I just greeted you buddy"
Wiki Markup |
---|
\[OPTIONAL\] Run OpenEJB iTests |
Install iTests
Simply copy the OpenEJB iTests war to the Tomcat webapp directory.
Code Block | ||||
---|---|---|---|---|
| ||||
apache-tomcat-6.0.14$ cp openejb-tomcat-3.0.0-SNAPSHOT-itests.war webapps/ |
Start Tomcat
Code Block | ||||
---|---|---|---|---|
| ||||
apache-tomcat-6.0.14$ bin/startup.sh
Using CATALINA_BASE: /your/tomcat/installation/apache-tomcat-6.0.14
Using CATALINA_HOME: /your/tomcat/installation/apache-tomcat-6.0.14
Using CATALINA_TMPDIR: /your/tomcat/installation/apache-tomcat-6.0.14/temp
Using JRE_HOME: /your/java/installation |
NOTE: Your output will be different from the example above due to differences in installation location.
Execute the test client
Code Block | ||||
---|---|---|---|---|
| ||||
$ java -Dtomcat.home=. -Dremote.servlet.url=http://127.0.0.1:8080/openejb/remote -jar openejb-tomcat-3.0.0-SNAPSHOT-test.jar tomcat _________________________________________________ |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| Running EJB compliance tests on HTTP/Tomcat Server _________________________________________________ WARNING: No test suite configuration file specified, assuming system properties contain all needed information. To specify a test suite configuration file by setting its location using the system property "openejb.testsuite.properties" test server = org.apache.openejb.test.TomcatRemoteTestServer entry = java.naming.provider.url:http://127.0.0.1:8080/openejb/remote entry = java.naming.factory.initial:org.apache.openejb.client.RemoteInitialContextFactory h1. \[OPTIONAL\] Run OpenEJB iTests h2. Install iTests Simply copy the OpenEJB iTests war to the Tomcat webapp directory. {code:none}apache-tomcat-6.0.14$ cp openejb-tomcat-3.0.0-SNAPSHOT-itests.war webapps/{code} h2. Start Tomcat {code:none}apache-tomcat-6.0.14$ bin/startup.sh Using CATALINA_BASE: /your/tomcat/installation/apache-tomcat-6.0.14 Using CATALINA_HOME: /your/tomcat/installation/apache-tomcat-6.0.14 Using CATALINA_TMPDIR: /your/tomcat/installation/apache-tomcat-6.0.14/temp Using JRE_HOME: /your/java/installation{code} *NOTE:* Your output will be different from the example above due to differences in installation location. h2. Execute the test client {code:none}$ java -Dtomcat.home=. -Dremote.servlet.url=http://127.0.0.1:8080/openejb/remote -jar openejb-tomcat-3.0.0-SNAPSHOT-test.jar tomcat _________________________________________________ |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| Running EJB compliance tests on HTTP/Tomcat Server _________________________________________________ WARNING: No test suite configuration file specified, assuming system properties contain all needed information. To specify a test suite configuration file by setting its location using the system property "openejb.testsuite.properties" test server = org.apache.openejb.test.TomcatRemoteTestServer entry = java.naming.provider.url:http://127.0.0.1:8080/openejb/remote entry = java.naming.factory.initial:org.apache.openejb.client.RemoteInitialContextFactory ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... .............................. ........... ........................ Time: 10.853 OK (885 tests) _________________________________________________ CLIENT JNDI PROPERTIES java.naming.provider.url = http://127.0.0.1:8080/openejb/remote java.naming.factory.initial = org.apache.openejb.client.RemoteInitialContextFactory _________________________________________________ {code} {tip:title=Failures} The tests should completely pass the first time they are run. If you execute the test client a second time, 21 tests fail for some unknown reason. {tip} {note:title=Useful instructions - Not properly integrated into this page. This info was picked up as is from an email from Dain} _Information below just put here temporarily so that we don't lose it, needs proper integration with original content_ The installer is still a work in progress (I'm working on it today), but the currently checked in version works fine on unix. David's process is correct, but here are the exact steps: 1. copy openejb-tomcat-3.0.0-SNAPSHOT-bin.zip to your Tomcat webapps directory 2. make sure Tomcat is running 3. visit http://localhost:8080/openejb/installer 4. Assuming you don't get any errors, reboot tomcat At this point OpenEJB will be installed just like the manual instructions (http://cwiki.apache.org/confluence/display/OPENEJB/New +Instructions). As for your applications, simply include EJBs in your war WEB-INF/classes or WEB-INF/lib/*.jar using either annotated classes or via a META-INF/ejb-jar.xml file. Restrictions o The installer only runs on Unix. Windows support will require a tweaked catalina.bat and a work around for Windows file locking. Cygwin won't work either and will require even more work arounds in the Unix code to deal with pathing problems. o There is no uninstaller. Currently, the installer deletes the non- compliant Tomcat annotations-api.jar so in addition to backing out the changes, you need to restore this file. o Annotations in servlets to OpenEJB resources (EJBs, PersistenceUnits, Topics, Queues, DataSources, etc) don't resolve. You will have to use global JNDI for the time being. o There is no security integration. I suggest you don't even try using secured EJB in Tomcat embedded mode yet. Hope this helps, o We only support Tomcat 6 and I suggest you use the newest version as I haven't tested any older 6 revisions. We could potentially support older versions of Tomcat if there were enough demand, but I doubt there will be since OpenEJB 3 requires Java5. {note}...... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ......................................... ........................ Time: 10.853 OK (885 tests) _________________________________________________ CLIENT JNDI PROPERTIES java.naming.provider.url = http://127.0.0.1:8080/openejb/remote java.naming.factory.initial = org.apache.openejb.client.RemoteInitialContextFactory _________________________________________________ |
Tip | ||
---|---|---|
| ||
The tests should completely pass the first time they are run. If you execute the test client a second time, 21 tests fail for some unknown reason. |