木曜日 12 25, 2008

前回は FELIX SHELL への接続方法を書きましたが、次は FELIX 上で直接 GlassFish を動かしてみましょう。今回もやはり GlassFish V3 Prelude は /home/shioda/glassfishv3-prelude にインストールされていることを前提に書いています。

まず、/home/shioda/glassfishv3-prelude/glassfish/felix/conf/system.properties ファイルをエディタで開きます。コメントアウトされた3つの変数が書かれていますので、これを自分の環境に合わせて変更しコメントアウトを外します。私の場合ですと次のようになります。

com.sun.aas.installRoot=/home/shioda/glassfishv3-prelude/glassfish/
com.sun.aas.instanceRoot=/home/shioda/glassfishv3-prelude/glassfish/domains/domain1/
com.sun.aas.installRootURI=file:///home/shioda/glassfishv3-prelude/glassfish/
このファイルの上の方にあるコメントに書いてありますが、asadmin などから起動するのであれば、これらの変数は launcher が面倒を見てくれるから設定する必要はありません。しかし今回は felix から直接起動ということで設定します。あとは felix を起動しましょう。

% java -jar /home/shioda/glassfishv3-prelude/glassfish/felix/bin/felix.jar

Welcome to Felix.
=================

Enter profile name: shioda
...
プロファイル名は何でも良いと思います。$HOME にそのプロファイルのデータが置かれるようです。
n% ls /home/shioda/.felix/shioda
bundle0    bundle114  bundle18   bundle34   bundle50   bundle67   bundle83
bundle1    bundle115  bundle19   bundle35   bundle51   bundle68   bundle84
bundle10   bundle116  bundle2    bundle36   bundle52   bundle69   bundle85
bundle100  bundle117  bundle20   bundle37   bundle53   bundle7    bundle86
bundle101  bundle118  bundle21   bundle38   bundle54   bundle70   bundle87
bundle102  bundle119  bundle22   bundle39   bundle55   bundle71   bundle88
bundle103  bundle12   bundle23   bundle4    bundle56   bundle72   bundle89
bundle104  bundle120  bundle24   bundle40   bundle57   bundle73   bundle9
bundle105  bundle121  bundle25   bundle41   bundle58   bundle74   bundle90
bundle106  bundle122  bundle26   bundle42   bundle59   bundle75   bundle91
bundle107  bundle123  bundle27   bundle43   bundle6    bundle76   bundle92
bundle108  bundle124  bundle28   bundle44   bundle60   bundle77   bundle93
bundle109  bundle125  bundle29   bundle45   bundle61   bundle78   bundle94
bundle11   bundle13   bundle3    bundle46   bundle62   bundle79   bundle95
bundle110  bundle14   bundle30   bundle47   bundle63   bundle8    bundle96
bundle111  bundle15   bundle31   bundle48   bundle64   bundle80   bundle97
bundle112  bundle16   bundle32   bundle49   bundle65   bundle81   bundle98
bundle113  bundle17   bundle33   bundle5    bundle66   bundle82   bundle99
FELIX SHELL は前回やったのと同様にポート 6666 にアクセスすれば使えます。
さて、前回は GlassFish V3 Prelude を Eclipse Equinox 上で動かす方法でしたが、今回はもともと使っている Apache Felix の OSGi 実行環境を見てみます。

OSGi の環境をいろいろ試すには、felix shell を使いたいので、この環境をセットアップします。 GlassFish V3 Prelude は、前回同様 /home/shioda/glassfishv3-prelude にインストールされていることを前提とします。まずエディタで /home/shioda/glassfishv3-prelude/glassfish/felix/conf/config.properties ファイルを開いてみてください。38行目から FELIX SHELL を使うには云々という説明が書いてありますが、簡単にいうと

${com.sun.aas.installRootURI}/felix/bundle/org.apache.felix.shell.jar \
${com.sun.aas.installRootURI}/felix/bundle/org.apache.felix.shell.remote.jar
この2行を felix.auto.start.1 の最後に追加しろということです。felix.auto.start.1 は次のようになります。
felix.auto.start.1= \
 ${com.sun.aas.installRootURI}/modules/javax.xml.stream.jar \
 ${com.sun.aas.installRootURI}/modules/tiger-types-osgi.jar \
 ${com.sun.aas.installRootURI}/modules/auto-depends.jar \
 ${com.sun.aas.installRootURI}/modules/config.jar \
 ${com.sun.aas.installRootURI}/modules/hk2-core.jar \
 ${com.sun.aas.installRootURI}/modules/osgi-adapter.jar \
 ${com.sun.aas.installRootURI}/felix/bundle/org.apache.felix.shell.jar \
 ${com.sun.aas.installRootURI}/felix/bundle/org.apache.felix.shell.remote.jar
あとはこの数行下に osgi.shell.telnet.port=6666 という設定があるのがわかると思います。これは FELIX SHELL に接続するポートになります。特に問題なければそのままにしておきましょう。他のアプリケーションでこのポートを使っている場合は値を変更してください。

さて、この設定が終わったらアプリケーションサーバーを起動します。

% /home/shioda/glassfishv3-prelude/glassfish/bin/asadmin start-domain --verbose
GlassFish が起動したら、他の端末からポート 6666 にアクセスしてみましょう。
% telnet localhost 6666
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

Felix Shell Console:
=====================

-> help
bundlelevel   ... |  - set or get bundle start level.
cd []                     - change or display base URL.
headers [ ...]                  - display bundle header properties.
help                                - display impl commands.
install  [ ...]           - install bundle(s).
packages [ ...]                 - list exported packages.
ps [-l | -s | -u]                   - list installed bundles.
refresh [ ...]                  - refresh packages.
resolve [ ...]                  - attempt to resolve the specified bundles.
services [-u] [-a] [ ...]       - list registered or used services.
shutdown                            - shutdown framework.
start  [  ...]         - start bundle(s).
startlevel []                - get or set framework start level.
stop  [ ...]                - stop bundle(s).
uninstall  [ ...]           - uninstall bundle(s).
update  []                 - update bundle.
version                             - display version of framework.
->
ぜひ皆さんもお試しください。

水曜日 12 24, 2008

GlassFish V3 Prelude での新しい機能の1つに OSGi サポートというのがあるのはご存じの方も多いかと思います。 OSGi の実行環境としては Apache Felix OSGi 実装を使っていますが、ほかの OSGi 実装で動かないかというとそんなこともありません。1月ほど前になりますが、 GlassFish v3 Prelude OSGi support: Is it really true? というブログの記事が java.net に投稿されていますので、この記事に沿って実際に Eclipse の Equinox 上で GlassFish V3 Prelude を動かしてみましょう。

用意するもの

  • GlassFish V3 Prelude:こちらからダウンロードしてください
  • Eclipse Equinox: こちらから eclipse-equinox-3.4.zip をダウンロードしてください
  • 設定ファイル(config.ini):こちらからダウンロードしてください
  • まず、GlassFish V3 Prelude をインストールします。今回は例として glassfish-v3-prelude-ml.zip を私のホームディレクトリ /home/shioda で展開(unzip)します。すると、/home/shioda/glassfishv3-prelude に GlassFish がインストールされます。

    % cd /home/shioda
    % unzip glassfish-v3-prelude-ml.zip
    
    次に /home/shioda/glassfishv3-prelude/glassfish ディレクトリで eclipse-equinox-3.4.zip を展開します。
    % cd /home/shioda/glassfishv3-prelude/glassfish
    % unzip eclipse-equinox-3.4.zip
    
    すると、eclipse Equinox のファイルが eclipse ディレクトリの下にインストールされます。 次に config.ini ファイルを /home/shioda/glassfishv3-prelude/glassfish/eclipse/configuration ディレクトリにコピーします。
    % cd /home/shioda/glassfishv3-prelude/glassfish/eclipse
    % mkdir configuration
    % cd configuration
    % cp ~/config.ini /home/shioda/glassfishv3-prelude/glassfish/eclipse/configuration
    
    設定の最後として、config.ini ファイルの最初の数行を GlassFish のインストールディレクトリに合わせて変更します。その前に UNIX 上で config.ini ファイルを開くと、改行コードが異なるために編集しにくい場合もあるので、改行コードを変更してしまいましょう。
    % cat config.ini | tr "[\r]" "[\n]" > config.ini.new
    
    そしてエディタで config.ini.new の以下の3つの行を環境に合わせて変更します。
    # GlassFish required properties
    com.sun.aas.installRoot=/home/shioda/glassfish-v3-prelude/glassfish/
    com.sun.aas.instanceRoot=/home/shioda/glassfish-v3-prelude/glassfish/domains/domain1/
    # HK2 OSGi Adapter property
    org.jvnet.hk2.osgiadapter.contextrootdir=/home/shioda/glassfish-v3-prelude/glassfish/modules
    
    
    私の場合は C: となっているところを /home/shioda に書き換えただけです。そして、config.ini.new を config.ini に rename してください。
    % mv config.ini config.ini.orig
    % cp config.ini.new config.ini
    
    これで準備はほぼ終了です。実行する場合は環境変数 GlassFish_Platform に Equinox を設定します。C Shell の場合は次のようにします。
    % setenv GlassFish_Platform Equinox
    
    そして、GlassFish を起動します。
    % /home/shioda/glassfishv3-prelude/bin/asadmin start-domain --verbose
    
    警告メッセージが出てきますが、これは既知の問題点です。本当に動いているかどうか確認するには http://localhost:8080/ にアクセスしてみてください。 今回私は Solaris 上で動かしましたが、ブログの記事は Windows 上で動かしているようですし環境依存の部分もなさそうですから他の環境でも動くだろうと思います。ぜひ皆さんもお試しください。 また、他の OSGi 環境上で動かせるようであればぜひ GlassFish チームにレポートしてあげてください。

    This blog copyright 2008 by shioda