---
title: "JBoss3学习笔记"
author: "fanjava"
date: "2004-06-25T20:17:00Z"
tags: []
slug: "jboss3"
draft: false
lastmod: "2004-06-25T20:17:00Z"
id: 602032
url: "https://fanjava.iteye.com/blog/602032"
---

目 录

一． 运行环境

二． 准备工作

三． 安装

四． 配置实例xPetStore

- 1\. 创建JBOSS“xpetstore”服务
- 2\. 配置JMS
- 3\. 配置JDBC
- 4\. 配置JavaMail
- 5\. 启动JBOSS
- 6\. 指定xPetStore的应用服务器
- 7\. 指定数据库
- 8\. Build源代码
- 9\. 发布应用
- 10\. 初始化数据库
- 11\. 运行应用
- 12\. 意外错误排除

五． 结束语

\--------------------------------------------------------------------------------

一． 运行环境  
操作系统：Windows 2000

应用服务器：Jboss3.x

数据库：MySQL4.x

虚拟机： SUN JDK1.4.x

\--------------------------------------------------------------------------------

二． 准备工作  
1．请安装JDK1.4.x版本，设置JAVA\_HOME变量，并把 “{%JAVA\_HOME%}\\bin” 加入Path中。

2．请下载Jboss3.x。主站地址 [http://www.jboss.org/](http://www.jboss.org/) 。

3．请下载并安装MySQL4.x。主站地址 [http://www.mysql.org/](http://www.mysql.org/) 。

4\. 请下载xpetstore3.x。主页地址 [http://xpetstore.sourceforge.net/](http://xpetstore.sourceforge.net/) 。

\--------------------------------------------------------------------------------

三． 安装  
1． 把压JBOSS下载文件解压。本文假设解压后路径为 C:\\Work\\jboss-3.2.2RC2。

2． 设置JBOSS\_HOME变量。进行命令窗口，运行bin目录下的run.bat命令。请注意后台有没有抛出异常。

3． 约半分钟后启动完毕，请访问 [http://localhost:8080/jmx-console/](http://localhost:8080/jmx-console/) 。如果成功显示页面，说明安装成功。

4． 进行命令窗口，运行bin目录下的 shutdown.bat -S 命令可以停止JBOSS。

\--------------------------------------------------------------------------------

四． 配置实例xPetStore  
1\. 创建JBOSS“xpetstore”服务  
在JBOSS\_HOME/server/下新建目录xpetstore，并把JBOSS\_HOME/server/default下的内容拷贝到xpetstore下。

2\. 配置JMS  
Create JBOSS\_HOME\\server\\xpetstore\\deploy\\jms\\jbossmq-destinations-xpetstore-service.xml to create JMS queues queue/order and queue/mail.

This xml file should look like this:

queue/order jboss.mq:service=DestinationManager queue/mail jboss.mq:service=DestinationManager  
3\. 配置JDBC  
Copy the JDBC driver to JBOSS\_HOME/server/xpetstore/lib。

Create JBOSS\_HOME/server/xpetstore/deploy/mysql-ds.xml. (Do NOT change the hsqldb-ds.xml, keep it.)

Edit mysql-ds.xml to create the datasource java:/xpetstoreDS。

JBOSS\_HOME/server/xpetstore/deploy/mysql-ds.xml should look like this:

xpetstoreDS jdbc:mysql://localhost/xpetstore com.mysql.jdbc.Driver thatway thatway 5 HsqlDbRealm  
4\. 配置JavaMail  
Create the Mail-Sesion java/:Mail.

Make sure that JBOSS\_HOME/server/xpetstore/deploy/mail-service.xml look like this:

Mail your-user-name your-password  
5\. 启动JBOSS  
cd JBOSS\_HOME/bin run.bat -c xpetstore  
6\. 指定xPetStore的应用服务器  
Download and unzip the xpetstore3.1.x file.

Edit the file XPETSTORE\_HOME/conf/as/appserver.properties and set the property app.server=jboss. You may want to review XPETSTORE\_HOME/conf/as/jboss.properties to make sure that all the properties are properly set.

7\. 指定数据库  
Edit the file XPETSTORE\_HOME/conf/db/database.properties and set the property db.name=mysql.

Edit the file XPETSTORE\_HOME/conf/db/mysql.properties to configure the database.You must set the following properties:

db.driver db.url db.user db.password db.classpath  
PS: Don't change the hibernate properties.

8\. Build源代码  
cd XPETSTORE\_HOME/xpetstore-servlet , run build.bat :

build.bat  
This command will :

Generate Java code in XPETSTORE\_HOME/xpetstore-servlet/build/java

Generate the deployment descriptors at XPETSTORE\_HOME/xpetstore- servlet/build/META-INF and XPETSTORE\_HOME/xpetstore- servlet/build/WEB-INF

Compile the source code and build .jar, .war and .ear files at XPETSTORE\_HOME/dist

经测试，事实上这样build是不足够的，在发布运行的过程中会出错。但考虑到官方文件是这样说的，并且这些的确是正确的主要步骤。之所以不能运行，完全是“意外”问题。因此，我们暂且跳过，到运行时再把步骤补全。

9\. 发布应用  
build.bat deploy  
10\. 初始化数据库  
build.bat db  
11\. 运行应用  
[http://localhost:8080/xpetstore-servlet/](http://localhost:8080/xpetstore-servlet/)

12\. 意外错误排除  
第一次build的过程会抛出xpetstore-servlet\\build\\META-INF not found的错误。此时，可以手工在相应目录建立META-INF文件夹。再运行build。

再发布时会抛出错误：Exception processing TLD at resource path /META-INF/taglib.tld。此时，可以手工将XPETSTORE\_HOME\\lib\\main\\com.opensymphony.module.webwork\\webword.jar\\META-INF中的taglib.tld 拷贝到XPETSTORE\_HOME\\xpetstore-servlet\\web\\META-INF目录下。（META-INF是手工建立的）。再编辑XPETSTORE\_HOME\\xpetstore-servlet\\build.xml，在“WAR”栏加入以下语句把taglib.tld拷贝进war中。再运行build。

发布时还会提出错误，主要原因是Hibernate getConnection时不能通过JBOSS的安全验证。此时，要修改JBOSS\_HOME/server/xpetstore/conf/login\_config.xml和JBOSS\_HOME/server/xpetstore/deploy/mydql\_ds.xml。

先说login\_config.xml。参照HsqlDbRealm段，添加如下代码。

jboss.jca:service=LocalTxCM,name=xpetstoreDS  
再到mysql\_ds.xml。修改security-domain值。

MysqlDbRealm

注意1：修改login-config.xml需要重启JBOSS才生效；修改mysql.xml则不必。

注意2：调试的过程中必然会多次重启JBOSS，如果xpetstore还没有发布成功的话，重启前请删除deploy目录下的xpetstore发布文件。

五． 结束语  
至此，我们的痛苦就结束了。请访问 [http://localhost:8080/xpetstore-servlet/](http://localhost:8080/xpetstore-servlet/) 看一看自己辛劳的成果。

此番配置有两个目的，一是熟悉JBOSS，二是便于学习xpetstore源代码。第一个目标我们是达到了，但第二个目标现在才开始，所以让我们一起共勉，继续努力。