Jboss 服务器下的部署说明文档
Document Sample


Jboss 服务器下的部署说明文档
一.Jboss 服务器的安装:
解压缩 jboss-3.2.3.zip 到本机磁盘即可, 无需安装, 以下我们以 Jboss_Home 代表 Jboss
的安装路径(如 D:\jboss-3.2.3) 。
配置 java 的运行环境,在系统环境变量中添加 JAVA_HOME。
现在就可以启动 Jboss 服务器了。Jboss 的启动命令是 Jboss_Home\bin\run.bat。双击
启动即可。
二.数据源的配置: (以 DB2 为例说明)
1. 将数据库驱动文件对应的 jar 或 zip 拷贝到 Jboss_Home\server\default\lib 目
录下.(本例中驱动程序为 db2java.zip)
2.将 数 据 源 配 置 文 件 Jboss_Home\docs\examples\jca\db2-ds.xml 拷 贝 到
Jboss_Home\server\default\deploy 目录下,并修改其中的:jndi-name,数据库实
例名,用户名和密码。如下例所示:
<datasources>
<local-tx-datasource>
<jndi-name>MySQLDS</jndi-name>
<connection-url>jdbc:db2:ASPDB</connection-url>
<driver-class>COM.ibm.db2.jdbc.app.DB2Driver</driver-class>
<user-name>db2admin</user-name>
<password>sduasp</password>
<min-pool-size>0</min-pool-size>
<metadata>
<type-mapping>DB2</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
3.对远程数据源,可以直接将远程数据源所在主机的 ip 写在<connection-url>中,
也可以通过在本机配置 db2 客户端来配置数据源
4.JBoss 为 j2ee 应用的 EJB 和 Web 模块分别使用了 jboss.xml 和 jboss-web.xml 描述符。
而标准的 j2ee 规范针对 EJB 和 Web 模块还分别定义了 ejb-jar.xml 和 web.xml 描述
符。
数据源的配置信息也需要写在这四个文件中。 (注: 如果所有访问数据库均是在 ejb
中完成,则没有必要将数据源配置在 jboss-web.xml 和 web.xml 中)修改如下:
在 Jboss.xml 中按下面所示的代码更改:
<entity>
<ejb-name>ProgrammerBMP</ejb-name> 声明的 ejb
<jndi-name>ejb/ProgrammerBMP</jndi-name> ejb 的 jndi 名
<resource-ref> 资源引用的起始标记
<res-ref-name>datasource</res-ref-name>被应用的资源名称
<jndi-name>java:/MySQLDS</jndi-name> jndi 名:必须为 java:/*
的形式
</resource-ref> MySQLDS 为数据源的 JNDI 名称,对应*-ds.xml 中配
置,Jboss 会根据此处的名称在*-ds.xml 查找对应的
数据源。如下段程序所示
<method-attributes></method-attributes>
</entity>
在 ejb-jar.xml 中
<entity >
<description><![CDATA[ProgrammerBMPBean]]></description>
<display-name>ProgrammerBMPBean</display-name>
<ejb-name>ProgrammerBMP</ejb-name>
<home>com.liuyang.bmp.programmer.ProgrammerBMPHome</home>
<remote>com.liuyang.bmp.programmer.ProgrammerBMP</remote>
<ejb-class>com.liuyang.bmp.programmer.ProgrammerBMPBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<resource-ref >
<res-ref-name>datasource</res-ref-name> 被应用的资源名称
<res-type>javax.sql.DataSource</res-type>被应用的资源类型
全称
为
<res-auth>Container</res-auth> 认证类型, Bean 或 Container
</resource-ref>
</entity>
在 jboss-web.xml 中(注: 如果所有访问数据库均是在 ejb 中完成,则省略此步)
<jboss-web>
<resource-ref>
<res-ref-name>datasource</res-ref-name>
<jndi-name>java:/MySQLDS</jndi-name>
</resource-ref>
</jboss-web>
在 web.xml 中(注:如果所有访问数据库均是在 ejb 中完成,则省略此步)
<web-app>
<display-name>ASPWeb</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<resource-ref >
<res-ref-name>datasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
5.定义好数据源之后, 下面的问题就是如何在程序查找并使用数据源。 实例代码如下:
Context Ctx=new InitialContext();
DataSource ds=(DataSource)Ctx.lookup("java:comp/env/datasource");
DataConnection conn = ds.getConnection();
其中:"java:comp/env/datasource"格式必须是固定的。
三.EJB 模块的配置:
ejb 的定义和规则与 was 环境下没有任何区别,无需改动。需要更改的只是 jboss.xml
描述文件和客户端调用 ejb 的规则。具体描述如下:
在
1.Ejb 描述文件 ejb-jar.xml: jboss 和 was 服务器环境下完全相同, 都按照标准的 j2ee
规范书写。因此改变服务器时,此文件不用修改。
2.Jboss 还是用 Jboss.xml 作为专门的 ejb 描述文件。通过它实现 jndi 名到 ejb 名的重
定向。其书写规则同(二.4)中的 Jboss.xml 所示。
3.客户端查找并调用 ejb 的书写规则:
Context ctx=new InitialContext();
Object obj=ctx.lookup("ejb/ProgrammerBMP");
ProgrammerBMPHome =( ProgrammerBMPHome)PortableRemoteObject.
narrow(obj, ProgrammerBMPHome.class);
四.WEB 模块的配置:
web 模块需要打成 war 包。和 was 环境下不同之处,就是增加了一个 jboss-web.xml
描述文件。Jboss-web.xml 的修改方法同(二.4)中的 jboss-web.xml 所示。
五.打包部署
1.在 jboss 服务器下同样采用了 ear 企业包的部署方式。打包方法此处不再赘述。唯
一的不同点就是:在打 ASPWeb.war 包时需要加入 jboss-web.xml,在打 ASPEJB.jar
包时需要加入 jboss.xml
2.部署:将 ear 包拷贝到 Jboss_Home\server\default\目录下即可。
六.服务器端口和根的配置:
1.修改 application.xml:
<web>
<web-uri>ASPWeb.war</web-uri>
<context-root>/</context-root>
</web>
2.修改 Jboss_Home\server\default\ jbossweb-tomcat41.sar\META-INF \
jboss-service.xml 中第 94 行的 port="8080" 为 port="80"。
七.启动并运行服务器:
部署结束后,双击 Jboss_Home\bin\run.bat,就可以启动 Jboss 服务器。在 Jboss 的
控制台窗口中,会显示启动信息。包括 Jboss 所用的 java 运行环境,读取配置文件,
装载类库,装载客户部署的 ear、war、jar 包的信息等。
部署和启动JBoss组件的具体日志信息能够在运行JBoss的控制台浏览到。如下消息表明,JBoss
服务器成功运行(很明显,由于启动JBoss的时间和目标机器的配置不同,其给出的取值会不同):
[Server] JBoss (MX MicroKernel) [4.0.1 (build: CVSTag=JBoss_4_0_1 date=
200412230944)] Started in 47s:608ms
八.将 Jboss 做成 Windows 服务
对于 Linux 或 UNIX 操作系统而言,用户需要安装启动脚本(或者通知系统管理员来
完 成 此项任务)。其中, JBoss 的 bin 目录中存在 jboss_init_redhat.sh 和
jboss_init_suse.sh,这样两个脚本实例,用户也可以修改它们,以满足各自的具体
需求。对于 Windows 操作系统而言,用户可以借助于实用工具,比如 JavaService2,
从而将 JBoss 安装成系统服务。
下面说明使用比如 JavaService2 制作 Windows 服务的方法:
如果你不想知道太多,请在 Jboss_Home\bin\下建一个 startService.bat 文件,直接
将下面的这段代码拷贝到此文件中:
JBossService.exe -install "JBoss" C:\j2sdk1.4.1_02\jre\bin\server\jvm.dll
-Djava.class.path={JDK_HOME}\lib\tools.jar;D:\jboss-3.2.3\bin\run.jar
-start org.jboss.Main -stop org.jboss.Main -method systemExit -out
D:\jboss-3.2.3\server\default\log\stdout.log -err
D:\jboss-3.2.3\server\default\log\stderr.log -current D:\jboss-3.2.3
-manual
还需要拷贝 JBossService.exe 到此目录下。 然后双击 startService.bat 即可完成服
务的制作。 注意: 上面这段代码必须只占用一行, 不能分行。 你还必须根据自己 jboss
的安装路径修改 D:\jboss-3.2.3 为你自己机器的目录。
如果你想知道的更详细,请阅读下面的说明:
Installing(安装 Windows 服务)
The JavaService executable has no dependencies on any files or directories. This was intentional so that
it could easily be used with any Java software. Additionally, it does not have a dependency on the name
JavaService.exe. This means that you can, and probably should, rename it to something more
appropriate. This can be quite useful when checking the Task Manager to see how much CPU time a
particular service is using, or how many threads it has created. Instead of seeing multiple entries for
JavaService.exe you see a unique entry for each renamed version of the executable. Follow these
instructions to use JavaService with your Java application:
1. Unzip the archive into a directory appropriate for your application. The following files will be
extracted:
o bin/JavaService.exe - The service executable.
o bin/installTomcat4.bat - A sample usage to install the service for Tomcat 4.
o bin/installTomcat32.bat - A sample usage to install the service for Tomcat 3.2.
o bin/installTomcat31.bat - A sample usage to install the service for Tomcat 3.1.
o bin/installOrion.bat - A sample usage to install the service for Orion.
o bin/test_install_orion.bat - A test usage to invoke the Orion service installer.
o bin/test_uninstall_orion.bat - A test usage to remove the installed Orion service.
o bin/installJBoss.bat - A sample usage to install the service for JBoss 3.x.
o bin/test_install_jboss.bat - A test usage to invoke the JBoss service installer.
o bin/test_uninstall_jboss.bat - A test usage to remove the installed JBoss service.
o docs/documentation.html - This documentation.
o docs/license.html - The license for distributing this product.
o docs/overview.html - High-level introductory documentation.
o docs/history.html - Release notes and change history.
o docs/faq.html - Frequently-Asked Questions.
o docs/styles.css - Formatting stylesheet for HTML documentation.
2. Copy the JavaService.exe file to a directory appropriate for your application, and optionally
rename JavaService.exe to something more relevant.
3. Start a command prompt and change to the directory where the JavaService.exe is located.
4. Type 'JavaService.exe -install' followed by the proper parameters, as described below.
Be sure to use quotation marks around parameters with spaces (italics signify an application
dependent value):
o service_name (mandatory) - The name that you want to use for this service. This is
what the service will show up as in the service control manager.
o jvm_library (mandatory) - The location of the jvm.dll file that you want to use as your
Java Virtual Machine. For Sun's Java 2 SDK, this is usually
{JDK_HOME}\jre\bin\classic\jvm.dll or {JDK_HOME}\jre\bin\hotspot\jvm.dll.
o jvm_option* (optional) - Optionally specify any necessary parameters to pass to the
JVM upon invocation. These may include thing such as "-Djava.class.path=" to specify
a classpath or "-Xmx128m" to specify a maximum heap size of 128MB. Any parameters
that you need to use when invoking the java.exe command tool should be specified
here. There is no limit to the number of parameters specified.
o -start start_class (mandatory) - The name of the class that you wish to use when
starting the service. This must be the fully qualified class name.
o -method start_method (optional) - The name of the static method of the start_class
that you wish to call to start the service. The method must be static, must return type
void, and must take a String[] as its only parameter. If this parameter is not
specified it defaults to main.
o -params start_parameter+ (optional) - Any parameters to pass to the start_method
when starting the service. These will be passed in as the String[] parameter.
o -stop stop_class (optional) - The name of the class that you wish to use when stopping
the service. This must be the fully qualified class name. If no stop_class is specified,
the process containing the Virtual Machine is simply terminated when the service is
stopped.
o -method stop_method (optional, but only allowed if a stop_class was specified) - The
name of the static method of the stop_class that you wish to call to stop the service.
The method must be static, must return type void, and must take a String[] as its
only parameter. If this parameter is not specified it defaults to main.
o -params start_parameter+ (optional, but only allowed if a stop_class was specified) -
Any parameters to pass to the stop_method when stopping the service. These will be
passed in as the String[] parameter.
o -out out_log_file (optional) - A file into which System.out will be redirected. If this
parameter is not specified, System.out will not be redirected.
o -err err_log_file (optional) - A file into which System.err will be redirected. If this
parameter is not specified, System.err will not be redirected.
o -current current_dir (optional) - A directory to use as the current working directory for
the service. If this parameter is specified, all relative paths in the service will be relative
to relative to the specified directory.
o -path extra_path (optional) - An addition to the path for the service. The specified path
will be appended to the system path before the service is started. This can be used to
specify where additional DLLs that native libraries are dependent upon can be found.
o -depends other_service (optional) - Another NT service that must be running before
this particular java service can start. Will cause the named service to be started
automatically if required when starting the java service. Will also stop the java service
if the named service is stopped (usually with user confirmation first being requested by
Windows NT).
o -auto or -manual - Optional parameter indicating whether service should be run
automatically on system startup (default mode), or if it should be started on demand
using a manual command (i.e. net start service).
o -shutdown seconds (optional) - Specify the amount of time that may be taken during
processing of your shutdown/stop method. The value here is used as a timeout, so if
the method has not completed in this length of time, the JVM process will be
terminated to allow the service to shutdown completely.
A simple example might look like the following:
JavaService.exe -install "My Service" c:\jdk\jre\bin\classic\jvm.dll
-Djava.class.path=c:\app\classes.jar -start com.my.ExampleClass -err c:\app\stderr.txt
This would create a service that, when started, would create a JVM from the JDK in c:\jdk setting the
classpath to be c:\app\classes.jar. It would then call the main method of the com.my.ExampleClass
class with a String array of length 0 (no parameters). Anything written to System.err would be
redirected into the file c:\app\stderr.txt.
UnInstalling(卸载 Windows 服务)
1. Start a command prompt and change to the directory where the JavaService.exe is located.
2. Type 'JavaService.exe -uninstall' followed by the name of the service.
九.日志的输出详细程度配置:
由于 JBoss 3.2.1 开发采用了 Log4j 管理其日志信息(严格地讲,它扩展了 Log4j),
因此了解 Log4j 的机理,有助于理解 JBoss 3.2.1 管理日志的方式。
JBoss 3.2.1 采用 JMX 架构的同时,且以.xml 文件类型为配置文件,因此可以
找到位于目录:C:\jboss-3.2.1_tomcat-4.1.24\server\default\conf 下的 log4j.xml
文件。比如,其中一段配置示例如下:
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
</appender>
比如,为了调节 JBoss 3.2.1 控制台日志输出的详细程度(调整为 DEBUG 级别),
我们需要修改 value=”INFO”,将 INFO 改为 DEBUG。
如果目标读者在开发 Entity Beans,可以调节位于与 log4j.xml 文件同一目录下的
standardjboss.xml 文件(该文件主要是提供修改 EJB 相关的调试、运行、调优、部署参
数)。如果目标读者 Entity Beans 采用的<container-name>为 Standard CMP 2.x
EntityBean,则将其中的<call-logging>属性的取值改为 true。
<container-configuration>
<container-name>Standard CMP 2.x EntityBean</container-name>
<call-logging>false</call-logging>
<invoker-proxy-binding-name>entity-rmi-invoker</invoker-proxy-binding-name>
<sync-on-commit-only>false</sync-on-commit-only>
。。。。。。。。。
完成上述两步后,读者在调试 Entity Beans 时通过控制台,可以看到 Entity Beans
发出的 JDBC 调用细节。
Get documents about "