blob: c447a9c092fbff7222dc3c6f63811ee5f3da1f31 [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= OSGi を使用した NetBeans プラットフォームクイックスタート
:jbake-type: platform_tutorial
:jbake-tags: tutorials
:jbake-status: published
:syntax: true
:source-highlighter: pygments
:toc: left
:toc-title:
:icons: font
:experimental:
:description: OSGi を使用した NetBeans プラットフォームクイックスタート - Apache NetBeans
:keywords: Apache NetBeans Platform, Platform Tutorials, OSGi を使用した NetBeans プラットフォームクイックスタート
このドキュメントは、NetBeans プラットフォームアプリケーションで OSGi バンドルを統合する方法についての簡単なデモンストレーションです。
このチュートリアルの中心は、「 link:http://www.aqute.biz/Code/Download#sudoku[Peter Kriens 氏による Sudoku ゲーム]」に基づいた「hello world」シナリオです。Sudoku ゲームを構成する OSGi バンドルを、関連する必須の Equinox バンドルと一緒にインポートします。アプリケーションを配備すると、Web ブラウザで次のアプリケーションが使用できます。
image::http://netbeans.dzone.com/sites/all/files/sudokugame-4.png[]
この簡単なシナリオを終えたら、このチュートリアルの最後にある「参考情報」の節に一覧されている、さらに役立つシナリオも参照してください。
NOTE: NetBeans プラットフォーム用のアプリケーション開発のために、別々のバージョンの NetBeans プラットフォームをダウンロードする必要はありません。通常、NetBeans IDE でアプリケーションおよびモジュールを開発し、NetBeans プラットフォームおよびアプリケーションを実行するのに必要なモジュールのみを追加します。
== 環境の設定
上記に一覧されているソフトウェアのダウンロードのほかに、次に示す手順を実行して環境を整える必要があります。
[start=1]
1. ディスク上のファイルシステムに新しいフォルダを作成します。
[start=2]
1. Equinox ディストリビューションから、次のものをこのフォルダに入れます。
* javax.servlet_xxx.jar
* org.eclipse.equinox.ds_xxx.jar
* org.eclipse.equinox.http_xxx.jar
* org.eclipse.equinox.util_xxx.jar
* org.eclipse.osgi.services_xxx.jar
* org.eclipse.osgi_xxx.jar
[start=3]
1. 次の 2 つの Sudoku JAR を、上記の JAR があるフォルダへ入れます。
* aQute.sudoku.jar
* aQute.webrpc.jar
これで、インポートする OSGi バンドルが、集中管理された場所で使用可能になりました。この場所から、バンドルをアプリケーションに統合できます。
== アプリケーションの作成
すべての必須 OSGi バンドルが使用可能になったら、次のようにして新しい NetBeans プラットフォームアプリケーションを作成します。
[start=1]
1. 「ファイル」>「新規プロジェクト」を選択して、次のように、Equinox テンプレートを使用して Equinox 上に NetBeans プラットフォームアプリケーションを作成するオプションを選択します。
image::http://netbeans.dzone.com/sites/all/files/sudokugame-5.png[]
「次へ」をクリックします。
[start=2]
1. 次に示すように、アプリケーションの名前を指定します。
image::http://netbeans.dzone.com/sites/all/files/sudokugame-3.png[]
「完了」をクリックします。
[start=3]
1. 上記のテンプレートから作成されたアプリケーションを実行すると、アプリケーションのウィンドウに、アプリケーションを構成するすべての NetBeans モジュールおよび OSGi バンドルが表示されるのが確認できます。
== OSGi バンドルのインポート
上記に一覧されているソフトウェアのダウンロードのほかに、次に示す手順を実行して環境を整える必要があります。
[start=1]
1. 「プロジェクト」ウィンドウでアプリケーションを右クリックして「プロパティー」を選択し、「ライブラリ」タブを表示します。「クラスタを追加」をクリックして、上記の JAR があるフォルダに移動します。そのあと、JAR を「クラスタ」(アプリケーションに組み込まれる関連モジュールおよびバンドルの集まり) に変換する次のようなウィザードが開きます。
image::http://netbeans.dzone.com/sites/all/files/sudokugame-1.png[]
[start=2]
1. 上記のように、インポートするすべての OSGi バンドルを「有効」に設定して、アプリケーションの起動時にロードされて使用可能になるようにします。
[start=3]
1. 「完了」をクリックすると、「platform.properties」構成ファイルが更新されています。次のようになっているはずです。
[source,java]
----
cluster.path.extra=netbinox:\../../path/to/my/nbsudokugame/folder
disabled.modules.extra=org.netbeans.libs.felix
cluster.path=\
${nbplatform.active.dir}/harness:\
${nbplatform.active.dir}/platform:\
${cluster.path.extra}
disabled.modules=\
org.jdesktop.layout,\
org.netbeans.api.visual,\
org.netbeans.core.execution,\
org.netbeans.core.multiview,\
org.netbeans.insane,\
org.netbeans.libs.felix,\
org.netbeans.libs.jsr223,\
org.netbeans.modules.apisupport.harness,\
org.netbeans.modules.apisupport.tc.cobertura,\
org.netbeans.modules.autoupdate.services,\
org.netbeans.modules.autoupdate.ui,\
org.netbeans.modules.core.kit,\
org.netbeans.modules.favorites,\
org.netbeans.modules.jellytools.platform,\
org.netbeans.modules.jemmy,\
org.openide.compat,\
org.openide.execution,\
org.openide.options,\
org.openide.util.enumerations
nbplatform.active=default
----
NOTE: 上記の最初の行は、前に作成したフォルダの場所を示しています。
[start=4]
1. そのあと、スプラッシュ画面を表示しないことと、アプリケーションを配備するポートを指定するために、アプリケーションの「project.properties」構成ファイルに次の行を追加します。
[source,java]
----
run.args.extra=--nosplash -J-Dorg.osgi.service.http.port=8080
----
== アプリケーションの実行
これで、次に示す手順でアプリケーションを配備する準備が整いました。
[start=1]
1. アプリケーションを実行します。アプリケーションのすべての OSGi バンドルおよび NetBeans モジュールが配備されます。配備済みの OSGi バンドルおよび NetBeans モジュールを表示するアプリケーションも配備されます。このアプリケーションは、現在何が配備済みかを監視できるので、非常に便利です。
image::http://netbeans.dzone.com/sites/all/files/sudokugame-6_0.png[]
または、上記のウィンドウを提供するモジュール全体を削除します。そのあと、OSGi の統合に必要な、いくつかの JAR (ブートストラップ、起動、ファイルシステム、モジュールシステム、ユーティリティー、およびルックアップ) を除いて、上記のウィンドウに必要なすべてのモジュール (ウィンドウシステム、アクションシステム、およびその他すべて) を削除します。
[source,java]
----
cluster.path.extra=netbinox:\../../path/to/my/nbsudokugame/folder
disabled.modules.extra=org.netbeans.libs.felix
cluster.path=\
${nbplatform.active.dir}/harness:\
${nbplatform.active.dir}/platform:\
${cluster.path.extra}
disabled.modules=\
org.jdesktop.layout,\
org.netbeans.api.annotations.common,\
org.netbeans.api.progress,\
org.netbeans.api.visual,\
org.netbeans.core,\
org.netbeans.core.execution,\
org.netbeans.core.io.ui,\
org.netbeans.core.multiview,\
org.netbeans.core.nativeaccess,\
org.netbeans.core.output2,\
org.netbeans.core.ui,\
org.netbeans.core.windows,\
org.netbeans.insane,\
org.netbeans.libs.felix,\
org.netbeans.libs.jna,\
org.netbeans.libs.jsr223,\
org.netbeans.libs.junit4,\
org.netbeans.modules.apisupport.harness,\
org.netbeans.modules.apisupport.tc.cobertura,\
org.netbeans.modules.applemenu,\
org.netbeans.modules.autoupdate.services,\
org.netbeans.modules.autoupdate.ui,\
org.netbeans.modules.core.kit,\
org.netbeans.modules.editor.mimelookup,\
org.netbeans.modules.editor.mimelookup.impl,\
org.netbeans.modules.favorites,\
org.netbeans.modules.javahelp,\
org.netbeans.modules.jellytools.platform,\
org.netbeans.modules.jemmy,\
org.netbeans.modules.keyring,\
org.netbeans.modules.masterfs,\
org.netbeans.modules.nbjunit,\
org.netbeans.modules.options.api,\
org.netbeans.modules.options.keymap,\
org.netbeans.modules.print,\
org.netbeans.modules.progress.ui,\
org.netbeans.modules.queries,\
org.netbeans.modules.sendopts,\
org.netbeans.modules.settings,\
org.netbeans.modules.spi.actions,\
org.netbeans.spi.quicksearch,\
org.netbeans.swing.outline,\
org.netbeans.swing.plaf,\
org.netbeans.swing.tabcontrol,\
org.openide.actions,\
org.openide.awt,\
org.openide.compat,\
org.openide.dialogs,\
org.openide.execution,\
org.openide.explorer,\
org.openide.io,\
org.openide.loaders,\
org.openide.nodes,\
org.openide.options,\
org.openide.text,\
org.openide.util.enumerations,\
org.openide.windows
nbplatform.active=default
----
このようにすると、モジュール式の Web 開発に適した非 GUI アプリケーション (サーバーアプリケーション) を使用できるようになります。
[start=2]
1. これで、次の URL をブラウザに入力すると (または、プログラムで NetBeans UI ユーティリティー API URLDisplayer.getDefault() を使用して必要な場所でブラウザを開くと)、Sudoku ゲームの配備で定義されている「index.html」がブラウザで表示され、Sudoku ゲームを始めることができます。
[source,java]
----
http://localhost:8080/rpc/sudoku/index.html
----
お疲れさまでした。これで最初の OSGi バンドルが NetBeans プラットフォームアプリケーションに統合されました。
== 参考情報
これでチュートリアルが終了しました。NetBeans プラットフォームアプリケーションで OSGi バンドルを再利用するための手順を理解したら、次に、関連ドキュメントや、より高度なシナリオを参照してください。
* link:http://www.osgi.org/blog/2006_09_01_archive.html[Peter Kriens 氏と Sudoku ゲーム]
* link:http://wiki.apidesign.org/wiki/NetbinoxTutorial[Jaroslav Tulach 氏と Netbinox]
* Toni Epple 氏の OSGi/NetBeans link:http://eppleton.sharedhost.de/blog/?p=662[ブログエントリ]および link:http://eppleton.sharedhost.de/blog/?s=Frankenstein%27s+IDE[プレゼンテーション]
* Gunnar Reinseth 氏の NetBeans-EMF 統合 ( link:http://eclipse.dzone.com/emf-on-netbeans-rcp[パート 1]、 link:http://eclipse.dzone.com/emf-on-netbeans-rcp-2[パート 2])
* link:http://java.dzone.com/news/new-cool-tools-osgi-developers[OSGi 開発者のための新しい便利ツール]」も参照してください