JBoss

advertisement
JBoss
Angela Fogarolli
Angela.Fogarolli@dit.unitn.it
What is JBoss?
JBoss, The Most Popular Application
Server by the Open Source
community
* Developed in Open Source, JBoss is FREE SOFTWARE distributed
under the LGPL license.
* JBoss is a full-fledged, award-winning, Java application server.
* JBoss enjoys a #1 position in downloads with more than 5 million
downloads.
* JBoss enjoys a #1 position in development due to ease of use
features
* JBoss enjoys a #1 position in OEM/ISV due to the free and modular
nature
* JBoss enjoys a #3 position in IT production with a 25% market
share.
History
JBoss has established a track record of innovative Java middleware
design with full support of standard and cutting edge, beyond
the standards, research
* JBoss was started in 1999 as an open source EJB container.
* JBoss 2.x was a full J2EE 1.2 based server.
* JBoss 3.x is the current J2EE 1.3 production series.
* JBoss 4.x is the current J2EE 1.4 production version.
* JBoss 5.x is the current developer version.
JBoss 3.x is a full framework for you to build your own applications.
It is based on a Java microkernel (JMX) and service oriented
architecture (SOA).
JBoss 4.x is exploring aspect oriented middleware (AOM) and Java
based middleware independent of J2EE.
JBoss, The Features
JBoss is advanced middleware with a full J2EE based personality
that IT departments look for. But that is not all, the OEM and ISV
community embraced JBoss as a highly flexible service oriented
architecture on which to build their own products.








Full microkernel approach based on Java Management eXtensions
(JMX)
Fully hot-deployable and cyclable service layer with Service Archive
format (SAR)
Fully automated and net based installation with hot-deploy of
applications
Full J2EE 1.4 support (EJB, JCA, JSP, JMX, HTTP etc)
Full security implementation and JAAS integration
Full clustering of any java objects (EJB, HTTP, POJO)
Aspect Oriented Programming (AOP).
Fully supported by JBoss, Inc.
Installing JBoss
1. Obtain a JDK version 1.3.1 or later for your platform (>1.4.2
recommended, and 1.5.0_x for latter jboss versions, see JBoss
vs JDK) and install it.
2. It is important to make sure it is the JDK and not the JRE as the
compiler is required for JSPs and other functions.
3. JBoss 3.2.6 appears to require JDK 1.4.2 or better.
Main.boot():98 calls java.net.URLDecoder.decode(String s,
String enc), which is present in 1.4.2 but not in 1.3.1. This was
corrected for the 3.2.7 release which compiles and runs under
jdk 1.3
4. Obtain the latest production release
5. Unzip the sources into a directory that does not contain spaces
anywhere in the path. (Meaning do not put it in C:\Program
Files\bla)
6. Examine the JBossDirectoryStructure.
Running
1. make sure JAVA_HOME is set
on Linux: export JAVA_HOME=/path/to/j2sdk-1.4.2_0x
on Windows (NT based): right click on My Computer, click
on Advanced, click on set Environment Variables. Set
JAVA_HOME. Example: JAVA_HOME =
C:\progra~1\j2sdk1.4.2_03 remember no spaces.
2. add JAVA_HOME/bin to the beginning of your PATH
3. change directory to the location that you installed
JBoss
4. change directory to the bin directory
5. execute either the run.sh or run.bat
6. congratulations, you are running the default
configuration!
Configurations
JBoss comes with 3 different configurations which you
specify by passing a -c variable:
* default - run with no parameters or with "-c default"
o basic J2EE/EJB support with integrated Tomcat
* minimal - run with "-c minimal"
o minimal jmx kernel support (with a JNDI server CAUTION: EJBs will not deploy in this config !)
* all - run with "-c all"
o includes everything from default plus JBoss.NET for
web services, and larger scale services such as
clustering and IIOP.
Shutting Down
To shut down JBoss, run bin/shutdown(.sh/.bat) or
press ctrl-c in the running terminal window.
Alternatively, there are methods to shut down JBoss in
the JMXConsole (Look for type=Server under the
jboss.system domain and invoke the shutdown
operation).
The JMX Console
You can get a live view of the server by going to the
JMX console application at
http://localhost:8080/jmx-console
The JBoss Management Console which provides a
raw view of the JMX MBeans which make up the
server.
For example, find the service=JNDIView link and click on it. This particular
MBean provides a service to allow you to view the structure of the JNDI
namespaces within the server. Now find the operation called list near
the bottom of the MBean view page and click the invoke. The operation
returns a view of the current names bound into the JNDI tree, which is
very useful when you start deploying your own applications and want to
know why you can’t resolve a particular EJB name.
JBossDirectoryStructure
* bin: contains various scripts and associated files. This is
where the run and shutdown scripts, which start and stop
JBoss, reside.
* client: stores configuration and jar files which may be needed
by a Java client application or an external web container. You
can select archives as required or use jbossall-client.jar.
* docs: contains useful information
o docs/dtd: contains the XML DTD used in JBoss for
reference (these are also a useful source of documentation on
JBoss configuration specifics).
o examples: contains optional configurations.
* lib: jar files which are needed to run the JBoss microkernel.
You should never add any of your own jar files here.
...JBossDirectoryStructure
* server: each of the subdirectories in here is a different server
configuration.
o <config-name>: a server configuration started with the -c
<config-name> option
+ conf: configuration files including the bootstrap services
in jboss-service.xml
# props: default users/roles properties files for the jmx
console (from 4.0.2)
# xmdesc: XMBean descriptors for those MBeans with
extended descriptions
+ lib: static jar files for the services
+ deploy: services and applications that are hot deployed
+ data: data files that survive reboot
+ tmp: temporary files that do not survive reboot
+ work: work files for Tomcat
...JBossDirectoryStructure
o minimal: a minimal jndi and jmx kernel
o default: the default configuration (does not include
clustering or corba)
o all: all services including clustering and corba
+ farm: deployments in here are hot deployed
across
the cluster
+ deploy-hasingleton: deployments in here are
only
run on one node in the cluster at a
time
Choose your configuration
The configurations are under server/xxx and have their own tree
with conf, deploy, and lib. To deploy your applications you
need to take note of which configuration you are running and
put them in the appropriate deploy directory.
* default: The default configuration is used if you don't pass
any parameters to the run script. It contains everything you
need to run a stand-alone J2EE server.
* minimal: the bare minimum required to start JBoss. It starts
the logging service, a JNDI server and a URL deployment
scanner to find new deployments. This is what you would use
if you want to use JMX/JBoss to start your own services
without anything else from J2EE. This is just the bare server
there is no web container, no EJB or JMS.
* all: starts all the available services. This includes the
RMI/IIOP and clustering services and the web-services
deployer which aren't loaded in the default configuration.
Which version of the JDK is
required for which versions of
JBoss AS?
JBoss version series
compiles with JDK version
runs under JDK version
3.2.x
1.3/1.4
1.3/1.4/5.0
4.0.x
1.4/5.0
1.4/5.0
* JBoss AS 3.2.6 and 4.0.1 are the first to be fully functional under JDK 5.
* JBoss AS 3.2.6 doesn't run with JDK 1.3. This issue is fixed in the JBoss AS
3.2.7.
* JBoss AS 4.0.0 runs under JDK 1.5, but the jconsole utility will not work with it.
You need 4.0.1+, 3.2.7+ to use jconsole.
* The current group of 64 bit JVMs have some stability issues. Please do extensive
testing on the 64 bit JVM before using it in Production.
* 64 bit hardware does provide some performance gains for 32 or 64 bit JVMs.
* Since JBoss v4.0.3, compiling the server with JDKv1.4 and JDKv5 produces
somewhat different outputs. A JDKv1.4 compilation produces the classic
jboss distribution. A JDKv5 compilation includes JDK5 only features, like
EJB3.
Setup MySql Datasource
Download the driver
* First, http://www.mysql.com/products/connector/j/ appropriate
for your edition of mySQL.
* Next, untar/unzip it and extract the jar file.
* Copy the jar file into $JBOSS_HOME/server/xxx/lib, where xxx
is your config name (such as "default") NOTE: For JBoss
4.0.2, use the jar file mysql-connector-java-3.1.8-bin.jar, not
mysql-connector-java-3.1.8-bin-g.jar.
* Copy the $JBOSS_HOME/docs/examples/jca/mysql-ds.xml
file to $JBOSS_HOME/server/xxx/deploy
Setup MySql Datasource
Configure the datasource
* Edit the mysql-ds.xml file.
* Replace <jndi-name>MySqlDS</jndi-name> with your
datasource name. If you choose to make mySQL your default
database (DefaultDS), then call this DefaultDS and be sure to
delete the example $JBOSS_HOME/server/all/deploy/hsqldbds.xml which is also configured to be DefaultDS.
* Replace <connection-url>jdbc:mysql://mysqlhostname:3306/jbossdb</connection-url> with your
connection string. Generally you just need to replace mysqlhostname with your host. Be sure that your user has
permission to connect to that hostname.
* Set the user-name and hostname elements to your database
username and hostname
Application partitioning


EJB (business logic) jar file
Web (presentation logic) war file
Application ear file
WEB Part
Archivio war:



WEB-INF\classes
WEB-INF\web.xml
* file html…
EJB Part
Archivio jar:




classi compilate
META-INF\ejb-jar.xml
META-INF\jbosscmp-jdbc.xml
META-INF\jboss.xml
EAR
Archivio ear
•
META-INF\application.xml
•
file jar
•
file war
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
"http://java.sun.com/dtd/application_1_3.dtd">
<application>
<display-name>Prova application</display-name>
<module> <ejb>provaJboss.jar</ejb>
</module>
<module> <web> <web-uri>provaJbossWeb.war</web-uri>
<context-root>/prova</context-root>
</web>
</module>
</application>
Deploy
To deploy your application just put the ear file in your
server/deploy directory
How to develop an EJB
component
1.
2.
3.
4.
5.
6.
7.
8.
Write the .java files that compose your bean: the component
interfaces,home interfaces, enterprise bean class file, and any helper
classes you might need.
Write the deployment descriptor.
Compile the .java files from step 1 into .class files.
Using the jar utility, create an Ejb-jar file containing the deployment
descriptor and .class files.
Deploy the Ejb-jar file into JBoss by copying your Ejb-jar file into the deploy
folder.
Configure your EJB server, you might tune things such as database
connections.
Start JBoss and confirm that it has loaded your Ejb-jar file.
Optionally, write a standalone test client .java file. Compile that test client
into a .class file. Run the test client from the command line and have it
exercise your bean’s APIs.
Example
Develop an application that manage the
cabin of a ship.
Object to create:
 An entity bean cabin;
 A test client;
Database configuration

Copy the db driver (mysql-connector-java-3.0.15ga-bin.jar) in jboss/server/default/lib.

Create the database “cabin_db”in MySql
Get mysql started and then open a mysql client
and create the database [ create database
cabin_db; (; compreso)]

Put mysql-ds.xml in deploy directory.
Download