How to post an EJB on JBoss (free EJB Server).

zhaozj2021-02-08  288

Prepare file

Required software: JDK1.3 (for win), J2EE_1_2_1_SDK, JBoss2.0 (www.jboss.org)

Required documents: J2EE_1_2_1_SDK_DOC, DevGuide1_2_1

2. Prepare the environment

Install JDK1.3 (support JBoss), check the environment variables after installation, you can compile a small program to try it.

Install jboss2.0, run bin / run.bat after completion. JNDI port is 1099, the web port is 8080, you can try it with the browser, 1099 port will return a garbled, 8080 port returns empty.

3. Compile and package

According to the compilation example of the Getting Started in JavaTM 2 Enterprise Edition Developer's Guide (V1.2.1), CONVERTERAPP.EAR is generated with Deploy Tool package.

EjB-JAR-IC.jar from Jar -xvf Convertrapp.ear This is the three files and tools related to BEA-related files and tools to generate meta-info / *. XML files (so-called deployment descriptor).

Then run the jboss's deploy Tool Open EJB-JAR-IC.JAR, set JNDI Name to MyConverter. Then save. (This tool automatically generates JBoss Deployment Descriptor)

On the jboss / deploy directory, JBOSS will automatically release the bean in the JBoss / Deploy directory.

4. Run the client program test

Modify ConverterClient.java according to JBoss teaching documentation

Import javax.naming. *;

Import java.util.hashtable;

Import javax.rmi.portableremoteObject;

Import java.util.properties;

Import java.io.fileinputstream;

Import javax.rmi.portableremoteObject;

Import converter;

Import converterhome;

Public class convertern {

Public static void main (String [] args) {

Try {

Properties PROPS = New Properties ();

Properties sysprops = system.getproperties ();

Try {

ProPs.Load (New FileInputStream ("Test.properties"));

sysprops.putall (prOPs);

} Catch (Exception E)

{

System.err.Println ("Can't Read` Test.proprties');

System.exit (-1);

}

System.SetProperties (sysprops);

Context initial = new initialcontext ();

Object objref = initial.lookup ("myconverter");

Converterhome Home =

(Converterhome) PortableRemoteObject.narrow (Objref,

Converterhome.class;

Converter currencyconverter = home.create ();

Double amount = currencyconverter.dollartoyen (200.00);

System.out.println (String.Valueof (Amount)); Amount = CurrencyConverter.yentoeuro (200.00);

System.out.println (String.Valueof (Amount));

} catch (exception ex) {

System.err.Println ("Caught An Unexpected Exception!");

EX.PrintStackTrace ();

}

}

}

Test.properties file content is as follows

Java.naming.Factory.initial = org.jnp.interfaces.namingcontextFactory java.naming.provider.URL = xxx.xxx.xxx.xxx: 1099 (IP on the machine where jboss is located)

Then run CompileClient.bat and TestClient.bat, you can enjoy the joy of success.

转载请注明原文地址:https://www.9cbs.com/read-1090.html

New Post(0)