この章では、Eclipse IDE for Java EE Developers(Eclipse)のHeliosリリースとOracle Enterprise Pack for Eclipse(OEPE)11gR1(11.1.1.7)を、CoherenceベースのJavaアプリケーションをビルドおよび実行するように設定する方法について説明します。
この章では次の項について説明します。
Eclipse Heliosの構成済バージョンとOEPEプラグインがバンドルされたOEPE 11gR1(11.1.1.7)のオールインワン・バージョンをダウンロードできます。オールインワン・バージョンをインストールすることをお薦めします。
また、OEPEディストリビューションを単独でダウンロードし、既存のEclipse Heliosインストールにインストールすることもできます。OEPEのインストーラには、Oracle WebLogic Server、Oracle CoherenceおよびOracle ADF Runtimeが含まれています。
どちらかのバージョンをダウンロードするには、次のOracle Enterprise Pack for Eclipseページの「Downloads」タブを選択します。
http://www.oracle.com/technetwork/developer-tools/eclipse/overview/index.html
インストーラの指示に従ってください。次のURLでインストール手順を参照することもできます。
http://download.oracle.com/docs/cd/E15315_07/help/oracle.eclipse.tools.common.doc/html/install.html
このチュートリアルは、次のようなファイル・システムのルートに作成したeclipse
フォルダにEclipseをインストールすることを前提としています。
C:\eclipse\*
Eclipseを起動して、Coherenceとともに使用できるように構成するには:
端末ウィンドウを開き、PATH
環境変数がJava JDK(例: \oracle\product\jdk160_14_R27.6.5-32\bin
)を含むように設定されていることを確認します。Java SE(JDK)バージョン1.6以降の作業用インストールが必要です。
PATH
環境変数にJava JDKの\bin
フォルダが含まれていない場合は、変数を次のように設定してください。
Eclipseを起動します。
Eclipseの実行可能ファイルはeclipse.exe
です。eclipse
というディレクトリにEclipseを抽出した場合、eclipse.exe
は次の場所にあります。
C:\eclipse\eclipse.exe
Eclipseにより、「Workspace Launcher」ダイアログ・ボックスでワークスペースを設定または選択するよう求められたら、C:\home\oracle\workspace
と入力します。
図2-1に、パスC:\home\oracle\workspace
を選択した「Workspace Launcher」ダイアログ・ボックスを示します。
Eclipseが起動したら、メニュー・バーの「Java EE」パースペクティブを選択します。
図2-2に、「Java EE」パースペクティブ・ボタンの場所を示します。
Eclipse IDEで新しいプロジェクトを作成するには:
「File」→「New」→「Application Client Project」を選択します。
「New Application Client Project」ダイアログ・ボックスで、「Project name」に値(Coherenceなど)を入力します。
図2-3 「New Application Client Project」ダイアログ・ボックス
「Configuration」セクションで「Modify」をクリックします。「Project Facets」ダイアログ・ボックスで、「Oracle Coherence」チェック・ボックスを選択します。ドロップダウン・リストからバージョン「3.7」を選択します(表示されていない場合)。
Oracle Coherenceファセットを追加すると、coherence.jar
がプロジェクト・クラス・パスに自動的に追加されます。また、Project Explorerで使用可能な、よく使用される次の構成ファイルが作成されます。
coherence-cache-config.xml
: デフォルトのキャッシュ構成ファイル
pof-config.xml
: Portable Object Formatシリアライズの構成ファイル
tangosol-coherence-override.xml
: Oracle Coherenceで使用される操作設定およびランタイム設定のオーバーライド・ファイル
図2-4 「Project Facets」ダイアログ・ボックスでの「Oracle Coherence」の選択
「Save As」をクリックして、「Save Preset」ダイアログ・ボックスで構成の名前を入力します。たとえば、「Name」フィールドにCoherenceConfig
と入力し、「Description」フィールドにIncludes
Coherence
Facet
と入力します。
図2-5に、「Save Preset」ダイアログ・ボックスを示します。
「OK」をクリックして、「Save Preset」ダイアログ・ボックスを閉じます。「OK」をクリックして、「Project Facets」ダイアログ・ボックスを閉じます。
「New Application Client Project」ダイアログ・ボックスの「Application Client Module」ページで「Next」をクリックします。
「New Application Client Project」ダイアログ・ボックスの「Java」ページで「Next」をクリックして、デフォルト値を受け入れます。
「New Application Client Project」ダイアログ・ボックスの「Application Client Module」ページで「 Create a default Main class」を選択解除します。「Next」をクリックします。
「Coherence」ページ(図2-6を参照)で、Coherence 3.7ライブラリをユーザー・ライブラリとしてプロジェクトに追加します。
「Manage Library」アイコンをクリックし、「Preferences」ダイアログ・ボックスで「New」をクリックします。
「New User Library」ダイアログ・ボックス(図2-7を参照)でCoherence37と入力します。「System library (added to the boot class path)」チェック・ボックスを選択します。
「OK」をクリックして、「New User Library」ダイアログ・ボックスを閉じます。
「Preferences」ダイアログ・ボックスで、「Add JARs」をクリックしてcoherence.jar
ファイルをライブラリに追加します。「Coherenceのインストール」でファイル・システムにダウンロードしたCoherenceディストリビューションのcoherence.jar
ファイルの場所に移動します。
図2-8に、coherence.jar
ファイルを選択した「JAR Selection」ダイアログ・ボックスを示します。
「Preferences」ダイアログ・ボックスは図2-9のようになります。「OK」をクリックして、「Preferences」ダイアログ・ボックスを閉じます。
図2-9 Coherenceユーザー・ライブラリに定義されたcoherence.jarファイル
「Coherence」ページで「Coherence37」ライブラリを選択し、「Finish」をクリックします。
Eclipse IDEの「Project Explorer」ウィンドウに新しいプロジェクトと関連ファイルが表示されます。
Eclipse IDEでプロジェクトを右クリックします。「Run As」→「Run Configurations」を選択します。「Run Configurations」ダイアログ・ボックスで、「Oracle Coherence」→「New launch configuration」アイコンを選択します。キャッシュ・サーバー構成の名前としてDefaultCacheServer
を入力します。
「Project」で「Browse」をクリックし、「Project Selection」ダイアログ・ボックスでプロジェクトの名前を選択します。
「Main class」で、「Include system libraries when searching for a main class」チェック・ボックスを選択します。「Search」ボタンをクリックし、「Select Main Type」ダイアログ・ボックスでDefaultCacheServer
と入力します。「com.tangosol.net.DefaultCacheServer」を選択し、「OK」をクリックします。「Apply」をクリックします。「Main」タブは図2-10のようになります。
「Coherence」タブで「General」タブを選択します。「Browse」アイコンをクリックして、キャッシュ構成ファイルに移動します。ローカル記憶域を有効(キャッシュ・サーバー)にするように選択します。「Cluster port」に一意の値(3155
など)を入力します。「Apply」をクリックします。「Coherence」タブは図2-11のようになります。
図2-11 「Run Configurations」ダイアログ・ボックスの「Coherence」タブ
「Arguments」タブを開きます。「VM Arguments」フィールドに-showversion
と入力します。「Apply」をクリックします。
ダイアログ・ボックスの「Common」タブを開きます。「Shared file」ラジオ・ボタンをクリックし、「Browse」をクリックしてプロジェクトに移動します。「Apply」をクリックします。「Common」タブは図2-12のようになります。
図2-12 「Run Configurations」ダイアログ・ボックスの「Common」タブ
「Run」をクリックして、キャッシュ・サーバーを起動します。キャッシュ・サーバーが起動し、例2-1のような出力が表示されます。
例2-1 Eclipseコンソール・ウィンドウでのキャッシュ・サーバーの出力
java version "1.6.0_14" Java(TM) SE Runtime Environment (build 1.6.0_14-b08) Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode) 2011-03-14 17:08:24.053/0.281 Oracle Coherence 3.7.0.0 <Info> (thread=main, member=n/a): Loaded operational configuration from "jar:file:/C:/oracle/product/coherence/lib/coherence.jar!/tangosol-coherence.xml" 2011-03-14 17:08:24.116/0.344 Oracle Coherence 3.7.0.0 <Info> (thread=main, member=n/a): Loaded operational overrides from "jar:file:/C:/oracle/product/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml" 2011-03-14 17:08:24.147/0.375 Oracle Coherence 3.7.0.0 <Info> (thread=main, member=n/a): Loaded operational overrides from "file:/C:/home/oracle/workspace/InsertValue/build/classes/tangosol-coherence-override.xml" 2011-03-14 17:08:24.147/0.375 Oracle Coherence 3.7.0.0 <D5> (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml" is not specified Oracle Coherence Version 3.7.0.0 Build 22913 Grid Edition: Development mode Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 2011-03-14 17:08:24.397/0.625 Oracle Coherence GE 3.7.0.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "jar:file:/C:/oracle/product/coherence/lib/coherence.jar!/coherence-cache-config.xml" 2011-03-14 17:08:24.600/0.828 Oracle Coherence GE 3.7.0.0 <D4> (thread=main, member=n/a): TCMP bound to /130.35.99.213:8088 using SystemSocketProvider 2011-03-14 17:08:28.116/4.344 Oracle Coherence GE 3.7.0.0 <Info> (thread=Cluster, member=n/a): Created a new cluster "cluster:0x96AB" with Member(Id=1, Timestamp=2011-03-14 17:08:24.6, Address=130.35.99.213:8088, MachineId=49877, Location=site:us.oracle.com,machine:tpfaeffl-lap7,process:2412, Role=CoherenceServer, Edition=Grid Edition, Mode=Development, CpuCount=2, SocketCount=1) UID=0x822363D50000012EB6D79318C2D51F98 2011-03-14 17:08:28.116/4.344 Oracle Coherence GE 3.7.0.0 <Info> (thread=main, member=n/a): Started cluster Name=cluster:0x96AB Group{Address=224.3.7.0, Port=3155, TTL=4} MasterMemberSet ( ThisMember=Member(Id=1, Timestamp=2011-03-14 17:08:24.6, Address=130.35.99.213:8088, MachineId=49877, Location=site:us.oracle.com,machine:tpfaeffl-lap7,process:2412, Role=CoherenceServer) OldestMember=Member(Id=1, Timestamp=2011-03-14 17:08:24.6, Address=130.35.99.213:8088, MachineId=49877, Location=site:us.oracle.com,machine:tpfaeffl-lap7,process:2412, Role=CoherenceServer) ActualMemberSet=MemberSet(Size=1, BitSetCount=2 Member(Id=1, Timestamp=2011-03-14 17:08:24.6, Address=130.35.99.213:8088, MachineId=49877, Location=site:us.oracle.com,machine:tpfaeffl-lap7,process:2412, Role=CoherenceServer) ) RecycleMillis=1200000 RecycleSet=MemberSet(Size=0, BitSetCount=0 ) ) TcpRing{Connections=[]} IpMonitor{AddressListSize=0} 2011-03-14 17:08:28.163/4.391 Oracle Coherence GE 3.7.0.0 <D5> (thread=Invocation:Management, member=1): Service Management joined the cluster with senior service member 1 2011-03-14 17:08:28.319/4.547 Oracle Coherence GE 3.7.0.0 <D5> (thread=DistributedCache, member=1): Service DistributedCache joined the cluster with senior service member 1 2011-03-14 17:08:28.350/4.578 Oracle Coherence GE 3.7.0.0 <D5> (thread=ReplicatedCache, member=1): Service ReplicatedCache joined the cluster with senior service member 1 2011-03-14 17:08:28.413/4.641 Oracle Coherence GE 3.7.0.0 <D5> (thread=OptimisticCache, member=1): Service OptimisticCache joined the cluster with senior service member 1 2011-03-14 17:08:28.413/4.641 Oracle Coherence GE 3.7.0.0 <D5> (thread=Invocation:InvocationService, member=1): Service InvocationService joined the cluster with senior service member 1 2011-03-14 17:08:28.413/4.641 Oracle Coherence GE 3.7.0.0 <Info> (thread=main, member=1): Services ( ClusterService{Name=Cluster, State=(SERVICE_STARTED, STATE_JOINED), Id=0, Version=3.7, OldestMemberId=1} InvocationService{Name=Management, State=(SERVICE_STARTED), Id=1, Version=3.1, OldestMemberId=1} PartitionedCache{Name=DistributedCache, State=(SERVICE_STARTED), LocalStorage=enabled, PartitionCount=257, BackupCount=1, AssignedPartitions=257, BackupPartitions=0} ReplicatedCache{Name=ReplicatedCache, State=(SERVICE_STARTED), Id=3, Version=3.0, OldestMemberId=1} Optimistic{Name=OptimisticCache, State=(SERVICE_STARTED), Id=4, Version=3.0, OldestMemberId=1} InvocationService{Name=InvocationService, State=(SERVICE_STARTED), Id=5, Version=3.1, OldestMemberId=1} ) Started DefaultCacheServer...
ここでは、Eclipse IDEでのプロジェクトのビルドに含まれる一般的な作業について説明します。
Eclipse IDEで新しいJavaクラスを作成するには:
「Project Explorer」ウィンドウでプロジェクト・エントリを右クリックします。「New」→「Class」を選択します。
「New Java Class」ダイアログ・ボックスでパッケージ名を入力します。このチュートリアルでは通常、値はcom.oracle.handson
になります。
「Name」フィールドにクラスの名前を入力します。
「Which method stubs would you like to create?」で、次の操作を行います。
ファイルを実行可能にするには、「public static void main(String[]args)」を選択します。
新しいクラスのスーパークラス内のコンストラクタのスタブを追加するには、「Constructors from superclass」チェック・ボックスを選択します。
「Inherited abstract methods」がデフォルトで選択されています。このオプションを選択すると、実装する必要があるインタフェースのスーパークラスまたはメソッド内の抽象メソッドのスタブが追加されます。
「OK」をクリックして、Javaクラスを作成します。
図2-13に、「New Java Class」ダイアログ・ボックスを示します。
実行可能ファイルのランタイム構成を作成するには:
「Project Explorer」ウィンドウで実行可能ファイルの名前を右クリックします。「Run As」→「Run Configurations」を選択します。
「Oracle Coherence」→「New Launch Configuration」アイコンをクリックします。「Java Application」ノードを選択します。「New Launch Configuration」ボタンをクリックします。
新規構成の名前を入力します。「Main」タブの「Project」で、「Browse」ボタンをクリックして現在のプロジェクトの名前に移動します。「Search」ボタンをクリックして、ランタイム構成を作成している実行可能ファイルの名前に移動します。「Apply」をクリックします。
次の図に、「Run Configurations」ダイアログ・ボックスの「Main」タブを示します。
「Coherence」タブをクリックします。「General」タブで、よく使用する、構成のVMランタイム引数の多くを設定できます。ランタイム引数の例としては、キャッシュ構成ディスクリプタへのパスのほか、ローカル記憶域、ログ・レベル、クラスタ・ポートの値などがあります。
図2-15に、「Run Configurations」ダイアログ・ボックスの「Coherence」タブの「General」タブを示します。
Eclipse IDEでは、Eclipseコンソールで「Terminate」アイコンおよび「Remove all terminated launches」アイコンをクリックすることによって、実行中のキャッシュ・サーバーまたはクライアントを停止できます。
しかし、「Windows タスク マネージャー」ウィンドウを調べると、サーバーまたはクライアントに関連するJavaプロセス(java.exe
)がまだ実行中になっている場合があります。サーバーまたはクライアントの再起動時にエラーがスローされないようにするには、関連するJavaプロセスを削除する必要があります。「Windows タスク マネージャー」ウィンドウでJavaプロセスを選択し、「プロセスクの終了」をクリックしてください。
図 2-16に、Javaプロセスを選択した「Windows タスク マネージャー」ウィンドウを示します。