Intro to Orion, Part 1
c:\orionapp
\public_html
\classes
\orionapp
\objects
\utils
\beans
\Info
public_html
folder.
We will create a session bean called Info and place it in the orionapp\beans\Info
folder.
The objects
and utils
folders will be used for additional helper classes in Part 2 of this guide.J2EE_HOME
, value: c:\j2sdkee1.2.1
(or the folder you installed to)JAVA_HOME
, value: c:\jdk1.3
(same as above)PATH
and edit it.
Go to the end of the variable value and add ;c:\jdk1.3\bin;c:\j2sdkee1.2.1\bin
CLASSPATH
and edit it.
Go to the end of the variable value and add ;c:\j2sdkee1.2.1\lib\j2ee.jar;c:\orionapp\classes
.
The second half of that is the folder that you just created.Info.java
.
Make sure you save it to your orionapp\classes\orionapp\beans\Info
folder.
package orionapp.beans.Info; import javax.ejb.EJBObject; import java.rmi.RemoteException; public interface Info extends EJBObject { public String getMessage(String name) throws RemoteException; } |
InfoHome.java
.
package orionapp.beans.Info; import javax.ejb.*; import java.rmi.RemoteException; public interface InfoHome extends EJBHome { public Info create() throws CreateException, RemoteException; } |
InfoBean.java
.
package orionapp.beans.Info; import java.rmi.RemoteException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.naming.InitialContext; public class InfoBean implements SessionBean { public String getMessage(String name) { String rtn = "Hello, " + name + "!"; return rtn; } public void ejbCreate() { } public void setSessionContext( SessionContext ctx) { } public void ejbRemove() { } public void ejbActivate() { } public void ejbPassivate() { } public void ejbLoad() { } public void ejbStore() { } } |
getMessage
declared in the remote interface.
All we need now is a JSP.index.jsp
.
Make sure you save this file in the orionapp/public_html
folder.
<%@ page import=" javax.naming.*, javax.ejb.*, java.rmi.*, javax.rmi.PortableRemoteObject, orionapp.beans.Info.*" %> <HTML><HEAD><TITLE>Test</TITLE></HEAD> <BODY> <% // variables for the Info bean InfoHome iHome = null; Info iBean = null; // check for form data String name = request.getParameter("txtName"); // variable for String returned from Info bean String msg = null; // if form data was submitted.... if (name != null) { try { InitialContext ctx = new InitialContext(); iHome = (InfoHome)PortableRemoteObject.narrow(ctx.lookup("java:comp/env/ejb/orionapp/beans/Info"), InfoHome.class); iBean = iHome.create(); } catch(Exception e) { e.printStackTrace(); } msg = iBean.getMessage(name); %> Here is your message: <%= msg %> <% } // end if (name != null) else { %> <FORM METHOD="get" action="index.jsp"> <BR>Enter your name: <INPUT TYPE="text" name="txtName"><BR> <INPUT TYPE="submit" value="Submit"><BR> </FORM> <% } // end else %> </BODY></HTML> |
cmd
under Start > Run.
Type cd\orionapp\classes
to get to your classes folder.javac orionapp\beans\Info\*.java
deploytool
. If you set your PATH
correctly, this will start Sun's deploytool utility.
This utility can be used to assemble the EAR file that J2EE applications are commonly packaged in.
This utility will also create the necessary XML files for the application, freeing you from that task.c:\orion\applications
and name the file orionapp.ear
. Click New Application
.Next
.Jar Display Name
, enter Info
. Leave the Manifest Classpath window empty, but click Add
next to the Contents
window. Browse
for the Root Directory. Click to c:\orionapp
, then highlight classes
and click on Choose Root Directory
.
Make sure it says c:\orionapp\classes
as your Root Directory, as having the classes
folder as your root directory is very important.orionapp
, then beans
, then Info
. Highlight the three files that end in .class
by holding Ctrl as you click them, then click on Add
. The bottom window should show:OK
. Click Next
.orionapp.beans.Info.InfoBean
orionapp.beans.Info.InfoHome
orionapp.beans.Info.Info
session
, and should be stateless
.Info
.Next
then Finish
, because we will not use the advanced options presented in the rest of the wizard.Next
.public_html
.Contents
, click Add
. For Root Directory, navigate to c:\orionapp
, highlight public_html
and click Choose Root Directory
.
Your Root Directory should end in public_html
.index.jsp
and click Add
. Click Next
, then Finish
.Next
. Select JSP
. Click Next
.index.jsp
. For Web Component Display Name, enter index.jsp
. Click Finish
, because we will not use the advanced settings presented in the rest of the wizard.Local Applications
window, under orionapp
, click on public_html
. Click on the EJB References
tab.Add
. Click the box under Coded Name
and enter ejb/orionapp/beans/Info
.
Make sure Type is Session
.
Under Home
, enter orionapp.beans.Info.InfoHome
.
Under Remote
, enter orionapp.beans.Info.Info
.orionapp
in the Local Applications window, then go to Tools > Verifier. Click OK
. The verifier will run, and you should get no errors. Do not worry if you get a warning. Click Close
.default-web-site.xml
under Orion's config folder. Add the following line, before the </web-site>
tag:
server.xml
, also under Orion's config folder. Add the following line, before the </application-server>
tag:
cd\orion
, then java -jar orion.jar
to start Orion. Wait for it to deploy your application, then open a Browser and type http://localhost/orionapp/index.jsp
as the URL. If all goes well, your application will work!