1. Introduction to this section
This chapter mainly introduces JBoss (a free EJB server) and teaches you how to install JBoss and build your first EJB and client. About what EJB is and how to develop it. Many books on EJB are described here. The description information is run on the Windows platform. Of course, you can apply the information on other supported platforms (such as Linux ). 2. About JBoss
JBoss supports the EJB 1.1 and EJB 2.0 specifications. It is a container and server for managing ejbs. Similar to Sun's j2sdk Enterprise Edition (J2EE), The JBoss core service only provides EJB servers. JBoss does not include serverlers/JSP page web containers. Of course, JBoss can be bound to tomcat or jetty. JBoss requires relatively small memory and hard disk space. It can run well in 64 MB memory and several megabytes of space. Sun's J2EE requires a minimum of 128 MB of memory and 31 MB of hard disk space. The JBoss startup speed is 10 times faster than that of J2EE. In addition, it can embed SQL database servers for persistent bean processing and will be automatically started at startup. (J2EE load separation cloudscape SQL Server ).
One of the very good features is that JBoss can be "hot" deployed. The "hot" deployment means that the bean deployment simply copies the JAR file of the bean to the deployment path. If the bean has been loaded, uninstall JBoss and load a new bean version. If you need more JBoss features, you can view the JBoss Forum website. If yes, you can pay for jbossgroup LLC.
This chapter step by step helps you start distributed development with JBoss: how to create a simple bean, and how to deploy and test on the JBoss server.
3. Prerequisites
JBoss is written in pure Java and requires a java system compatible with jdk1.3. To make it cheaper and run all examples, you need ant 1.4 or later. The following section describes how to obtain and install the SDK. Of course, you must have the foundation for developing ejbs.
4. Install ant
We may have seen this name in many books and webpages. What is it used? Ant is a Java-based build tool. Many build tools, such as make, gnumake, nmake, and jam, are available. Ant is a cross-platform build tool. The reason why ant can be cross-platform is that ant no longer requires you to write shell commands. The ant configuration file is an XML-based task tree that allows you to run various tasks, tasks are executed by objects that implement specific task interfaces.
Two versions of binary and source are available to download the latest version 1.5.2.
Http://ant.apache.org/old-releases/v1.5.2/binaries/ (Binary)
Source: http://ant.apache.org/old-releases/v1.5.2/source/
For the differences between these two versions, see http://ant.apache.org /. If you can not download can ask me QQ: 182244794, email: amaryllis@163.net.
After downloading ant, decompress the file and put all the files in the Apache-ant-1.5.2 path. The ant document will be released in the docs/manual directory. You can open the webpage docs/manual/index.html to view the ant document content. I released it in the C:/Apache-ant-1.5.2 path in windows.
1) set the ant_home environment variable to point to your ant directory.
2) You need to set the java_home environment variable to point to your JDK directory.
3) add % ant_home %/bin to the path environment variable.
4) When you run ant without any parameters, ant will find a file named build. XML in the current directory. If not, the following message is displayed:
Buildfile: Build. XML does not exist! Build failed
To test whether ant has been installed successfully, I have created a new build. xml file and put it in the current directory % ant_home %/samples. The content of build. XML is as follows:
<! -- Simple ant build script to test an ant installation --> <br/> <Project name = "testinstall" default = "run" basedir = "."> <br/> <Target name = "init"> <br/> <Available file = "asimplehelloobject. Java" property = "asimplehelloobject"/> <br/> </Target> <br/> <Target name = "asimplehelloobject" Unless = "asimplehelloobject" depends = "init"> <br/> <ECHO file = "asimplehelloobject. Java"> <br/> Public class asimplehelloobject <br/> {<Br/> Public static void main (string [] ARGs) {<br/> System. Out. println ("asimplehelloobject. Main was called") ;}< br/> } <Br/> </Echo> <br/> <Echo message = "wrote asimplehelloobject. Java"/> <br/> </Target> <br/> <Target name = "compile" depends = "asimplehelloobject"> <br/> <Javac destdir = "." srcdir = "." DEBUG = "on" classpath = "."> <br/> <Include name = "asimplehelloobject. Java"/> <br/> </Javac> <br/> </Target> <br/> <Target name = "run" depends = "compile"> <br/> <Java classname = "asimplehelloobject" classpath = "."/> <br/> <Echo message = "ant appears to be successfully installed"/> <br/> </Target> <br/> </Project> <br/> |
The result of running ant is as follows:
C:/Apache-ant-1.5.2/samples> antbuildfile: Build. xml Init: Asimplehelloobject: [Echo] wrote asimplehelloobject. Java Compile: [Javac] compiling 1 source file to C:/Apache-ant-1.5.2/Samples Run: [Java] asimplehelloobject. Main was called [Echo] ant appears to be successfully installed Builde successful Total time: 11 seconds. |
Now the ant and environment you have installed have been set successfully. If the following warning is reported:
Warning: java_home environment variable is not set. If build fails because Sun. * classes cocould not be found you will need to set the java_home environment variable to the installation directory of Java.
Indicates that you need to set the java_home environment and specify the JDK directory you have installed. I will introduce how to use various commands in ant later. 5. Install JBoss
1) before installing and running JBoss, you must check whether JDK is installed. You must set the JDK directory in the PATH environment.
2) download the JBoss server. JBoss is a compressed file. You can download the latest version. To support web server, I used windows, so I downloaded jboss3.0.6-tomcat4.1.18. You can download it directly in the http://prdownloads.sourceforge.net/jboss. If you are using a UNIX/Lunix platform, you can also download the corresponding JBoss server from this URL.
3) Installation
(1) installation in Lunix/Unix
A. You have downloaded the JDK jar tool for the JBoss server L of UNIX/Lunix version to decompress the file to a temporary directory.
B. Set jboss_dist to point to the top-level directory after JBoss unzipping.
C. Go to this directory.
CD jboss_dist/bin
Sh run. SHL
After running, the following information is displayed:
Bash-2.04 $/bin/sh run. Sh
Jboss_classpath =: Run. jar: ../lib/Crimson. Jar
JBoss. Home =/tmp/JBoss-2.2.2
Using JAAS loginconfig: file:/tmp/JBoss-2.2.2/CONF/default/auth. conf
Using configuration "default"
[Info] Java version: 1.3.1, Sun Microsystems Inc.
[Info] Java VM: Java hotspot (TM) server VM 1.3.1-B24, Sun Microsystems Inc.
[Info] system: Linux 2.2.16-22, i386
[Shutdown] shutdown hook added
[Service Control] registered with server
[Service Control] initializing 24 mbeans
...
[Service Control] started 24 services
[Default] JBoss 2.2.2 started in 0 m: 7 S
(2) installation in Windows
A. Download jboss3.0.6-tomcat4.1.18.zip and decompress it to a directory using WinZip. I will decompress it to the C:/jboss3.0.6-tomcat4.1.18 directory.
B. After decompression, you do not need to configure it. Use the run. Bat command in the bin directory.
C. Run the run. Bat command. check whether any exceptions are thrown in the background.
D. If the job runs successfully, visit http: // localhost: 8083 and a blank page will appear. When you access http: // localhost: 8080, a welcome page for Tomcat appears. If the following error occurs: Apache Tomcat/4.1.12-HTTP status 500-no context configured to process this request, this is normal because you have not released it yet. ear or. war application. Of course, jboss-3.2.orc3_tomcat-4.1.18.zip won't have this problem, because the Web Test File webtest is included in the directory server/default/deploy. ear access http: // localhost: 8082 you can see the service started by JBoss. You can run http: // localhost: 8080/JMX-console.
(3) window NT and 2000 Supplement
For nt and Win2k systems, if you want to install NT or Win2k services, you can add JBoss to the system service to avoid running run in the JBoss directory every time. the bat command only automatically starts the JBoss server when the system starts.
A. download the file "assumervice.exe" first. L edit a batch of processed files, and save them to the same directory as assumervice.exe. I named it jboss_tomcat_service.bat. The content of this file @ echo offecho --------
Echo usage: % 0 jdk_home tomcat_home (Classic/hotspot/Server) echo Note: You may not use spaces in the path names. if you know howecho to fix this, please tell me. echo JDK 1.4 does not come with hotpot server by default, you mustecho install this seperately if you wish to use it. echo example: % 0 .. /JDK .. /jboss30 hotspot
Echo --------
If "% 1" = "Uninstall" Goto uninstall
If "% 1" = "-Uninstall" Goto uninstall
If "% 1" = "" Goto usage
If "% 2" = "" Goto usage
If "% 3" = "" Goto usage
If "% 1" = "-help" Goto usage
If "% 1" = "-? "Goto usage
If "% 1" = "/? "Goto usage
: Install
Assumervice.exe-install jboss306 % 1/JRE/bin/% 3/JVM. DLL-djava. class. path = % 1/lib/tools. jar; % 2/bin/run. jar-start Org. JBoss. main-Stop Org. JBoss. main-method systemexit-out % 2/bin/out.txt-current % 2/bin goto EOF
: Uninstall
Assumervice.exe-uninstall jboss306
Goto EOF
: Usage
Echo -------- to install JBoss 3.0.6 do
Echo usage: % 0 jdk_home jboss_home (Classic/hotspot/Server)
Echo Note: You may not use spaces in the path names. If you know how echo to fix this, please tell me.
Echo JDK 1.4 does not come with hotpot server by default, you must echo install this seperately if you wish to use it.
Echo example: % 0 ../JDK ../jboss30 hotspot
Echo --------
Echo -------- to uninstall JBoss 3.0.6 do
Echo usage: % 0 uninstall echo --------
Goto EOF
: EOF
E. Run the following command:
Jboss_tomcat_service C:/j2sdk1.4.0 _ 02 C:/jboss-3.0.6_tomcat-4.1.18 Server
C:/j2sdk1.4.0 _ 02 is the Java installation directory c:/jboss-3.0.6_tomcat-4.1.18 is the JBoss installation directory, server is the constant parameter
F. You will see the successfully installed command. You can view jboss306 service in Win2k or NT Service and you can start it normally. Then check the various web pages (the same as Windows installation). If the installation is successful, congratulations, you have installed the JBoss server.
(4) Problem
If the service is installed, the webpage displays incorrect. You need to try multiple times, first run
Jboss_tomcat_service uninstall
Then run
Jboss_tomcat_service C:/j2sdk1.4.0 _ 02 C:/jboss-3.0.6_tomcat-4.1.18 server.