在開發(fā)的過程中,我們可能需要將生產環(huán)境和調試環(huán)境分開來,這樣才能保證安全性,但是安裝兩個glassfish又不太可能,因為它太龐大了。另外做為一個工程發(fā)布也不太方便,每次都要將工程名改來改去,并且綁定的EJB在同一個域內里是不能同名的。這樣的話,要改變的東西實在是太多了。
我們可有以第三種方法,那就是為glassfish添加另外的domain,一個domain跑我們的真實環(huán)境,一個domain跑我們的測試環(huán)境,因為是同一個glassfish,所以也不會存在從測試到真實環(huán)境的移植問題。以后只要改一個domain就可以了。我們在安裝glassfish的時候,它已經默認為我們安裝了一個domain,那就是domain1.
我們查看setup.xml里面可以看出,是如何新建domain的,于是我們把我們需要的一些target提取了出來,見如下。下面的配置里面唯一可能需要改變的就是glassfish安裝目錄這個屬性了,其它可以按照我配的來,也可以自己修改。
<?xml version="1.0" encoding="UTF-8"?>
<project name="createDomain" default="create.domain" basedir=".">
<target name="setEnv">
<property name="domain.name" value="domain3"/>
<property name="admin.user" value="admin"/>
<property name="admin.password" value="adminadmin"/>
<property name="admin.port" value="6848"/>
<property name="instance.port" value="10080"/>
<property name="orb.port" value="5700"/>
<property name="imq.port" value="9676"/>
<property name="https.port" value="10181"/>
<property name="iiop.ssl" value="5821"/>
<property name="iiop.mutualauth" value="5921"/>
<property name="jmx.admin" value="10687"/>
<property name="install.home" value="C:/Program Files/glassfish-v2ur2"/>
<property name="adminpassfile" value="${install.home}/passfile"/>
<property name="ASADMIN" value="${install.home}/bin/asadmin.bat"/>
<echo file="${adminpassfile}" append="false">AS_ADMIN_ADMINPASSWORD=${admin.password}</echo>
</target>
<target name="create.domain" depends="setEnv">
<exec executable="${ASADMIN}" failonerror="true">
<arg line="create-domain" />
<arg line="--adminport ${admin.port}" />
<arg line="--instanceport ${instance.port}" />
<arg line="--user ${admin.user}" />
<arg line="--passwordfile "${adminpassfile}"" />
<arg line="--domainproperties orb.listener.port=${orb.port}:jms.port=${imq.port}:http.ssl.port=${https.port}:domain.jmxPort=${jmx.admin}:orb.ssl.port=${iiop.ssl}:orb.mutualauth.port=${iiop.mutualauth}" />
<arg line="--savelogin" />
<arg line="${domain.name}" />
</exec>
<delete file="${adminpassfile}" />
</target>
</project>
然后用ant執(zhí)行它就可以了,我這里的執(zhí)行輸出如下:
C:\Program Files\glassfish-v2ur2>ant
Buildfile: build.xml
setEnv:
create.domain:
[exec] Using port 6848 for Admin.
[exec] Using port 10080 for HTTP Instance.
[exec] Using port 9676 for JMS.
[exec] Using port 5700 for IIOP.
[exec] Using port 10181 for HTTP_SSL.
[exec] Using port 5821 for IIOP_SSL.
[exec] Using port 5921 for IIOP_MUTUALAUTH.
[exec] Using port 10687 for JMX_ADMIN.
[exec] Domain being created with profile:developer, as specified by variabl
e AS_ADMIN_PROFILE in configuration file.
[exec] The file in given locale [zh_CN] at: [C:\Program Files\glassfish-v2u
r2\lib\install\templates\locales\zh_CN\index.html] could not be found. Using def
ault (en_US) index.html instead.
[exec] Security Store uses: JKS
[exec] Domain domain3 created.
[exec] Login information relevant to admin user name [admin] for this domai
n [domain3] stored at [C:\Documents and Settings\hadeslee\.asadminpass] successf
ully.
[exec] Make sure that this file remains protected. Information stored in th
is file will be used by asadmin commands to manage this domain.
[delete] Deleting: C:\Program Files\glassfish-v2ur2\passfile
BUILD SUCCESSFUL
Total time: 21 seconds
C:\Program Files\glassfish-v2ur2>
這樣我們就可以看到glassfish的domains目錄下面,多出了一個domain3這個文件夾。然后有關數(shù)據庫連接池啊什么的,就可以到該目錄下面的config/domain.xml去改了,domain.xml里面的屬性我們以后有時候再好好研究一下。當然,我們也可以去glassfish的控制臺進行可視化修改,glassfish的控制臺是所有的應用服務器里面做得最好的一個了。訪問的端口就是我們新建domain的時候用到的
admin.port的這個屬性。
盡管千里冰封
依然擁有晴空
你我共同品味JAVA的濃香.
posted on 2008-10-14 22:59
千里冰封 閱讀(6022)
評論(2) 編輯 收藏 所屬分類:
JAVAEE