JBoss3.0.4 configuration and use initial

zhaozj2021-02-11  183

JBoss3.0.4 configuration and use initial

Friday, February 28, 2003

Foreword

JBoss launched version 3.0.4 is actually a long time, but, online about it is less pitiful, and only a few introductions are not completely correct, many or even directly copy JBoss 2.4.4 related content. Those plagiarists did not expect that there is a big leap from JBoss2.4.4 to JBoss3.0.4, and even the directory structure is different. The relevant configuration is not more, their copying works are not correctly instructed to learn JBoss. .

In order to learn JBoss, I think most people may have to download their own documents from http://www.jboss.org, such as the 3.x version has document jboss.0.0quickstart.draft3.pdf to get started guidance. But what is unidentified is that even there is even errors in jboss.3.0quickstart.draft3.pdf documentation, in accordance with its guidance, everyone will take it.

Therefore, combined with my recent experience in learning JBoss3.0.4, according to the practical application, I have summarized JBoss3.0.4 configuration and use initial documentation for your reference and discussion.

premise

First, you have to install JDK, version is 1.3 or more, I am using the 1.4 version. And set the Java_Home environment variable in ClassPath to the JDK installation directory. Make sure you can run Java programs on your machine.

Installation and run JBoss3.0.4

Download JBoss3.0.4 in JBoss's own website http://www.jboss.org Download JBoss3.0.4.4.4.zip and JBoss-3.0.4_tomcat-4.1.12.zip. The latter is a version of JBoss and Tomcat to join together. Here mainly introduces the former, which is separate JBoss3.0.4.

JBoss is running very simple. Unzip jboss-3.0.4.zip to a directory of the local hard drive. There will be the following directory generation:

bin

Place a JBoss startup and stop executable script file

DOCS

Place an example of JBoss, test scripts and DTDs of various script configuration files

Lib

Part of the JAR package file required to place JBoss

Client

Place the JAR package required for EJB client running

Server

Place the server-side EJB configuration required for each start-up type, etc.

JBoss3.0.4 has three start types, all of which are all, default, minimal. If JBOS is started under the Windows platform, you can directly start the run.bat under the bin directory. At this time, the default is to start in the form of default. If you need other boot mode, you will need a parameter setting. If you want to start with ALL mode, run the run.bat -c all command. As for the difference between the three starting modes, it is nothing more than how much the service is activated. Please refer to JBoss.3.0QUickStart.draft3.pdf documentation. This document also has a section of setting JBoss to start serving Windows services, or refer to it, but I try it in accordance with its practice, I found that actually JBoss's service will occupy more than 90% of CPU resources (I used to use Caiyang 233, blush in……).

As everyone's see, JBoss is so simple, and it is not necessary to make additional configurations in their own machines. To this step, everyone is very cool. OK, let us continue

View jboss port

This should not be a chapter alone, but all online information and jboss.3.0quickstart.draft3.pdf are misleaded in this part. I want to clarify it here.

After starting JBOSS, we can view the 8080 port. Type http: // localhost: 8080 in the browser address bar, we will find an error page, the content is "http error: 404 / not found requesturi = /" This is normal Because you don't have a page at all, you can display it. When viewing 8082 ports in accordance with online information and jboss.3.0quickstart.draft3.pdf, we will find that it is inconsistent in fundamental and information. JBoss.3.0quickStart.draft3.Draft3 is this: "To check if jboss is running please open a browser and enter http: // localhost: 8082 Which Will List All Jboss Components Running." But we will appear An error page! It is not like it will list all running JBoss components. After searching, it is found that it should be http: // localhost: 8080 / jmx-console. This point is noted that otherwise it will hit the initiator to learn the interest of JBoss. We use this page to configure and manage the services of JBoss.

Let's view http: // localhost: 8083 will have a blank page with no errors, normally, it should be like this.

Let's take another http: // localhost: 1099 will have a large stack of characters. Of course, it contains similar information such as your IP address and so on. 1099 is the default port of the JNP protocol listening to the name service, and the default port of RMI is also the same. In JNDI, we need this port.

OK, basic port information is these.

EJB file writing

The EJB structure is not the content we discussed. Here is just to list its program code, it is a stateless sessionbean. Here I use EJB2.1 JAR.

Remote interface file: eXample.java

Package examples;

Import javax.ejb.ejbobject;

Public interface example extends ejbobject {

Public string example () throws java.rmi.remoteexception;

}

HOME interface file: examplehome.java

Package examples;

Import javax.ejb.ejbhome;

Public interface examplehome extends ejbhome {

Example Create () throws java.rmi.remoteException, javax.ejb.createException;

}

Local interface file: exampleelocal.java

Package examples;

Import javax.ejb.ejblocalobject;

Public Interface ExampleLocal Extends EJBLOCALOBJECT {

Public String Example ();

}

LocalHome interface file: exampleelocalhome.java

Package examples;

Import javax.ejb.ejblocalhome;

Public interface exampleLocalhome extends ejblocalhome {

ExampleLocal create () throws javax.ejb.createException;

}

Bean file: eXampleBean.java

IMPORT JAVA.RMI.RemoteException;

Import javax.ejb.ejbexception;

Import javax.ejb.sessionbean;

Import javax.ejb.sessionContext;

Public class examplebean implements sessionbean {

Public examplebean () {

Super ();

}

Public void setsessionContext (sessioncontext arg0)

Throws ejbexception, remoteException {

System.out.println ("SetSessionContext");

}

Public void ejbcreate ()

{

System.out.println ("ejbcreate");

}

Public void ejbremove () THROWS EJBEXCEPTION, RemoteException {

System.out.println ("ejbremove");

}

Public void ejbactivate () throws ejbexception, remoteexception {

System.out.println ("ejbactivate");

}

Public void ejbpassivate () THROWS EJBEXCEPTION, RemoteException {

System.out.println ("ejbpassivate");

}

Public String Example ()

{

System.out.println ("example ()");

Return "Just A Simple Example!";

}

}

Client call program file: ExampleClient.java

Package examples;

Import javax.naming. *;

Import javax.rmi.portableremoteObject;

Import java.util.properties;

Public class exampleclient {

Public exampleclient () {

Super ();

}

Public static void main (String [] args) {

Try {

Properties PROPS = New Properties ();

Props.put (Context.Initial_Context_Factory, "Org.jnp.Interfaces.namingContextFactory);

Props.Put (Context.Provider_URL, "172.16.1.4:1099");

Context CTX = New InitialContext (PrOPS);

System.out.println ("Start Ejb Client Test");

Object obj = ctx.lookup ("eXample");

Examplehome Home = (Examplehome) PortableRemoteObject.narrow (Obj, ExampleHome.Class);

EXAMPLE EXAMPLE = home.create ();

System.out.println (Example.example ());

EXAMPLE.REMOVE ();

} catch (Exception E)

{

E.PrintStackTrace ();

}

}

}

EJB package

We need to make a Class file compiled by the above file into a JAR package, deploying to jboss to call the ExampleClient execution test. This JAR package can be any name, named it myfirst.jar.

Follow the package paths of the above files, form an examples directory after normal compile, and store each Class file below. In the same-level directory with the Examples, you also need to create a meta-inflicity, which will place the various configuration files required for the EJB.

In Meta-INF, we need two files EJB-JAR.XML and JBoss-Service.xml. EJB-JAR.XML files will include various critical information of EJB, while jboss-service.xml includes some of the key information to deploy EJB deployed on JNDI. General online information will only introduce the ejb-jar.xml file, but for JNDI deployment, there is almost no, and some are also inherited from jboss2.4.4, named jboss.xml, but in jboss3.0.4, it Will not recognize this name, only JBoss-Service.xml is recognized.

The ejb-jar.xml file content is as follows:

Your First EJB Application

Just A Test

Example

Examples.examplehome

Examples.example

Examples.exampleLocalHome

Examples.exampleLocal

Examples.exampleBean

stateless

Container

List the name of EJB and the class paths and class names of each interface and beans.

The JBoss-Service.xml content is as follows:

Example

EXAMPLE

True

List the name of EJB and the location name of the EJB in JNDI, which is important for multiple EJB deployments. With these directories and files, you can pack it. Run commands in the Examples and Meta-INF-like directory:

JAR CVF myfirst.jar Examples / *. Class meta-inf / *. xml

After the execution, we have a MyFirst.jar package, including directory Examples and Meta-INF, and Class and XML files in the corresponding directory.

At this point, we have formed an EJB JAR package that can be performed under different EJB containers. Here is to describe how to specifically deploy our Myfirst.jar in JBoss3.0.4.

Deployment in EJB in JBoss3.0.4

Just write EJB-JAR.XML and JBOSS-Service.xml, deploying EJB in JBoss3.0.4 is very simple.

Different start JBoss mode, put the JAR file in the corresponding directory. For example, we started with the run -c all command, then put myfirst.jar in the all / deploy directory under the Server directory, at this time, the running JBoss automatically identifies and according to META-INF / * in JAR. .xml automatically deploy it.

Then the deployment of EJB is complete.

EJB operation

We run ExampleClient to verify our EJB program.

When compiling exampleclient.java, classpath needs to introduce the JAR file under the JBoss directory client to compile success and run normally.

Run ExampleClient and appear on the client:

Start EJB Client Test

Just A Simple Example!

At the server, the following statement will appear:

13: 35: 31,250 Info [stdout] setsessionContext

13: 35: 31,250 Info [stdout] EJBCREATE

13: 35: 31,250 info [stdout] example ()

Prove that our EJB successfully runs in jboss3.0.4! !

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

New Post(0)