query: tag:java

 Spring Rooの最もベーシックな使い方はroo shell上でentityコマンドを使ってEntityを作成していくやり方ですが、既にDB上にテーブルが存在していて、そのテーブルをEntityとして使用するアプリケーションを作ることもできます。

 Rooのインストール、プロジェクトの作成、DBの接続設定までは同様の手順で行います。

Spring Roo Install

[Spring Roo]プロジェクト作成, Logging&DB接続設定

 これ以降の手順は下記ページを参考に実施していきます。

Chapter 9. Incremental Database Reverse Engineering (DBRE) Add-On

 Database Reverse Engineering(DBRE)アドオンには database introspect と database reverse engineer の2つのコマンドがありますが、いずれかを初めて実行した場合にはJDBCドライバのインストールを促すプロンプトが表示されます。

sh>>
com.example roo> database introspect --schema no-schema-required
Located add-ons that may offer this JDBC driver
2 found, sorted by rank; T = trusted developer; R = Roo 1.1 compatible
ID T R DESCRIPTION -------------------------------------------------------------
01 - Y 9.0.0.801_jdbc4_0001 PostgreSQL #jdbcdriver...
02 Y Y 9.0.801.0001 Postgres #jdbcdriver driverclass:org.postgresql.Driver....

[HINT] use 'addon info id --searchResultId ..' to see details about a search result
[HINT] use 'addon install id --searchResultId ..' to install a specific search result, or
[HINT] use 'addon install bundle --bundleSymbolicName TAB' to install a specific add-on version
JDBC driver not available for 'org.postgresql.Driver'
<<--

 ここで addon info コマンドを使うことで検出されたドライバの詳細情報を見ることが出来ます。

sh>>
com.example roo> addon info id --searchResultId 01
Name.........: spring-roo-postgres-jdbc4-wrapper
BSN..........: org.postgresql.roo.wrapper.postgresql
Version......: 9.0.0.801_jdbc4_0001
Roo Version..: 1.1
Ranking......: 0.0
JAR Size.....: 546943 bytes
PGP Signature: 0x36673F56 signed by Ingo Thierack (ingothierack@googlemail.com)
OBR URL......: http://spring-roo-postgres-jdbc4-wrapper.googlecode.com/svn/repo/
repository.xml
JAR URL......: httppgp://spring-roo-postgres-jdbc4-wrapper.googlecode.com/svn/re
po/org/postgresql/roo/wrapper/org.postgresql.roo.wrapper.postgres
ql/9.0-801.jdbc4.0001/org.postgresql.roo.wrapper.postgresql-9.0-8
01.jdbc4.0001.jar
Description..: PostgreSQL #jdbcdriver driverclass:org.postgresql.Driver. This
bundle wraps the standard Maven artifact:
postgresql-9.0-801.jdbc4.
<<--

 最新のドライバをインストールするために、下記コマンドを実行します。

sh>>
com.example roo> addon install id --searchResultId 01
Download URL 'http://spring-roo-postgres-jdbc4-wrapper.googlecode.com/svn/repo/org/postgresql/roo/wrapper/org.postgresql
.roo.wrapper.postgresql/9.0-801.jdbc4.0001/org.postgresql.roo.wrapper.postgresql-9.0-801.jdbc4.0001.jar' failed
This resource was signed with PGP key ID '0x36673F56', which is not currently trusted
Use 'pgp key view' to view this key, 'pgp trust' to trust it, or 'pgp automatic trust' to trust any keys
Target resource(s):

spring-roo-postgres-jdbc4-wrapper (9.0.0.801_jdbc4_0001)

Deploying...done.

Unable to install add-on: spring-roo-postgres-jdbc4-wrapper [version: 9.0.0.801_jdbc4_0001]
<<--

 おや、インストールに失敗してしまいました。どうやらドライバのダウンロードURLのKeyが信頼されていないということのようです。pgp key view コマンドを使用してkeyの情報を表示します。

sh>>
com.example roo> pgp key view --keyId 0x36673F56

KEY ID: 0x36673F56 <<<<
More Info: http://keyserver.ubuntu.com/pks/lookup?fingerprint=on&op=index&search=0x36673F56
Created: 2011-1-30 18:36:08 +0000
Fingerprint: dc1a2679fc6a938d6681a61389a2afd036673f56
Algorithm: RSA_GENERAL
User ID: Ingo Thierack ingothierack@googlemail.com
Signed By: Key 0x36673F56 - not locally trusted
Subkey ID: 0x1A2EDAED [RSA_GENERAL]
<<--

 このKeyを信頼してダウンロードを可能にするために、下記コマンドを実行します。

sh>>
com.example roo> pgp trust --keyId 0x36673F56
Added trust for key:

KEY ID: 0x36673F56 <<<<
More Info: http://keyserver.ubuntu.com/pks/lookup?fingerprint=on&op=index&search=0x36673F56
Created: 2011-1-30 18:36:08 +0000
Fingerprint: dc1a2679fc6a938d6681a61389a2afd036673f56
Algorithm: RSA_GENERAL
User ID: Ingo Thierack ingothierack@googlemail.com
Signed By: Key 0x36673F56 (Ingo Thierack ingothierack@googlemail.com)
Subkey ID: 0x1A2EDAED [RSA_GENERAL]
<<--

 そして再度インストールコマンドを実行します。

sh>>
com.example roo> addon install id --searchResultId 01
Target resource(s):

spring-roo-postgres-jdbc4-wrapper (9.0.0.801_jdbc4_0001)

Deploying...done.

Successfully installed add-on: spring-roo-postgres-jdbc4-wrapper [version: 9.0.0.801_jdbc4_0001]
[Hint] Please consider rating this add-on with the following command:
[Hint] addon feedback bundle --bundleSymbolicName org.postgresql.roo.wrapper.postgresql --rating ... --comment "..."
<<--

 無事にインストールできました。次にDBREアドオンのdatabase introspectコマンドでテーブルの情報を表示します。

sh>>
com.example roo> database introspect --schema public --file --enableViews
<<--

 出力内容は割愛しますが、XML形式でスキーマの情報が表示されます。

 そして実際にテーブル情報からEntityを作成するためにdatabase reverse engineerコマンドを実行します。

sh>>
com.example roo> database reverse engineer --schema public --package ~.domain --testAutomatically
Created SRC_MAIN_RESOURCES\dbre.xml
Updated ROOT\pom.xml
Updated SRC_MAIN_RESOURCES\META-INF\persistence.xml
Created SRC_MAIN_JAVA\com\example\domain
Created SRC_MAIN_JAVA\com\example\domain\Access.java
Created SRC_MAIN_JAVA\com\example\domain\Content.java
Created SRC_TEST_JAVA\com\example\domain
Created SRC_TEST_JAVA\com\example\domain\AccessDataOnDemand.java
Created SRC_TEST_JAVA\com\example\domain\AccessIntegrationTest.java
Created SRC_TEST_JAVA\com\example\domain\ContentDataOnDemand.java
Created SRC_TEST_JAVA\com\example\domain\ContentIntegrationTest.java
Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_Configurable.aj
Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_Entity.aj
Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_DbManaged.aj
Created SRC_MAIN_JAVA\com\example\domain\Access_Roo_ToString.aj
Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_Configurable.aj
Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_Entity.aj
Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_DbManaged.aj
Created SRC_MAIN_JAVA\com\example\domain\Content_Roo_ToString.aj
Created SRC_TEST_JAVA\com\example\domain\AccessDataOnDemand_Roo_Configurable.aj
Created SRC_TEST_JAVA\com\example\domain\ContentDataOnDemand_Roo_DataOnDemand.aj
Created SRC_TEST_JAVA\com\example\domain\AccessDataOnDemand_Roo_DataOnDemand.aj
Created SRC_TEST_JAVA\com\example\domain\ContentIntegrationTest_Roo_Configurable.aj
Created SRC_TEST_JAVA\com\example\domain\ContentIntegrationTest_Roo_IntegrationTest.aj
Created SRC_TEST_JAVA\com\example\domain\ContentDataOnDemand_Roo_Configurable.aj
Created SRC_TEST_JAVA\com\example\domain\AccessIntegrationTest_Roo_Configurable.aj
Created SRC_TEST_JAVA\com\example\domain\AccessIntegrationTest_Roo_IntegrationTest.aj
<<--

 --schemaオプションで対象のDBスキーマを、--packageオプションでEntityを作成するパッケージを指定します。--testAutomaticallyを指定することでEntityのインテグレーションテストが自動的に作成されます。

 また、--excludeTablesオプションや--includeTablesオプションで対象のテーブルを特定のテーブルに限定することも出来ます。

 これ以降の手順は、roo shellからEntityを作成したあとと同じ手順でWebアプリケーションのセットアップなどを行うことが出来ます。

posted by akanuma akanuma on Tue 20 Dec 2011 at 08:54 with 0 comments

 Cloud Foundryに申し込んで使えるようになったので、Spring Roo in Actionの11章を参考にRooのアプリケーションをデプロイしてみました。

 まずはroo shellからCloud Foundryを走査するためのAddonをインストールします。インストールの間自動的に認証されるよう、下記コマンドを実行します。

sh>>
roo> pgp automatic trust
Automatic PGP key trusting enabled (this is potentially unsafe); disable by typing 'pgp automatic trust' again
<<--

そして下記コマンドでAddonをインストールします。

sh>>
roo> addon install bundle --bundleSymbolicName org.springframework.roo.addon.cloud.foundry;1.1.5.RELEASE
Target resource(s):

Spring Roo - Addon - Cloud Foundry (1.1.5.RELEASE)

Required resource(s):

Spring Beans (3.0.5.RELEASE)
jcl-over-slf4j (1.6.1)
slf4j-nop (1.6.1)
Spring AOP (3.0.5.RELEASE)
Servlet Specification API (2.5.0)
Spring Core (3.0.5.RELEASE)
Jackson JSON processor (1.6.2)
Data mapper for Jackson JSON processor (1.6.2)
Spring Context (3.0.5.RELEASE)
Spring Roo - Wrapping - aopalliance (1.0.0.0010)
Spring Web (3.0.5.RELEASE)
slf4j-api (1.6.1)
Spring Roo - Wrapping - Cloud Foundry API (0.0.1.0010)

Optional resource(s):

Spring Expression Language (3.0.5.RELEASE)
Spring ASM (3.0.5.RELEASE)

Deploying...done.

Successfully installed add-on: Spring Roo - Addon - Cloud Foundry [version: 1.1.5.RELEASE]
[Hint] Please consider rating this add-on with the following command:
[Hint] addon feedback bundle --bundleSymbolicName org.springframework.roo.addon.cloud.foundry --rating ... --comment "..
."
<<--

Roo in Actionの例では "addon install bundle --bundleSymbolicName org.springframework.roo.addon.cloud.foundry" という感じにバージョン番号を指定していないのですが、これだと最新のバージョンがインストールされます。今回のケースではSpring Rooのバージョンが1.1.5なので、Addonのインストールでもバージョンを1.1.5に指定しないとこの時点の最新である1.2.0.RC1がインストールされてしまい、うまくいきません。

インストールが終了したら自動認証をOFFに戻します。

sh>>
roo> pgp automatic trust
Automatic PGP key trusting disabled (this is the safest option)
<<--

Addonをインストールしたことでcloud foundryコマンドが使用できるようになっています。まずはCloud Foundryにログインします。

sh>>
roo> cloud foundry login --email xxxxxxxxxx@xxxxx.xxx --password xxxxxxxxxx
Credentials saved.
Logged in successfully with email address 'xxxxxxxxxx@xxxxx.xxx'
<<--

Cloud Foundryの環境についての情報を表示するには下記コマンドを実行します。

sh>>
roo> cloud foundry info

VMware's Cloud Application Platform
For support visit http://support.cloudfoundry.com

Target: http://api.cloudfoundry.com (0.999)

User: hiroaki.akanuma@gmail.com
Usage: Memory (128MB of 2048MB total)
Services (0 of 16 total)
Apps (1 of 20 total)
<<--

現在デプロイされているアプリケーションのリストは下記コマンドで確認できます。

sh>>
roo> cloud foundry list apps

=================================== Applications ===================================

Name Status Instances Services URLs


akanumahello STARTED 1 akanumahello.cloudfoundry.com
<<--

上記の出力では akanumahello というアプリケーションがすでにデプロイされていることが分かります。

また、現在使用可能なサービスのリストは下記コマンドで確認できます。

sh>>
roo> cloud foundry list services

======================= System Services ========================

Service Version Description


mysql 5.1 MySQL database service
postgresql 9.0 PostgreSQL database service (vFabric)
mongodb 1.8 MongoDB NoSQL store
redis 2.2 Redis key-value store service
rabbitmq 2.4 RabbitMQ messaging service

There are currently no provisioned services.
<<--

ではアプリケーションをデプロイしてみます。cloud foundry deploy コマンドでデプロイすることができます。

sh>>
roo> cloud foundry deploy --appName cftest --path CREATE
~~中略~~
Operation could not be completed: 400 Bad Request
<<--

上記のように 400 Bad Request となってしまった場合は、--appName で指定したアプリケーション名がすでに使われているということなので、アプリケーション名を変更して再度デプロイします。

sh>>
roo> cloud foundry deploy --appName cftestaka --path CREATE
~~中略~~
The application 'cftestaka' was successfully pushed
<<--

上記のように successfully pushed と出力されればデプロイ成功です。アプリケーションの一覧を確認してみます。

sh>>
roo> cloud foundry list apps

=================================== Applications ===================================

Name Status Instances Services URLs


akanumahello STARTED 1 akanumahello.cloudfoundry.com
cftestaka STOPPED 1 cftestaka.cloudfoundry.com
<<--

cftestakaというアプリケーションが一覧に追加されています。StatusがSTOPPEDになっていてまだ起動はしていないので、下記コマンドでアプリケーションを起動します。

sh>>
roo> cloud foundry start app --appName cftestaka
The application 'cftestaka' was successfully started
roo> cloud foundry list apps

=================================== Applications ===================================

Name Status Instances Services URLs


akanumahello STARTED 1 akanumahello.cloudfoundry.com
cftestaka STARTED 1 cftestaka.cloudfoundry.com
<<--

Status が STARTED に変わり、アプリケーションが起動されました。http://cftestaka.cloudfoundry.com/ にアクセスしてトップページが表示されれば起動に成功しています。

稼働中のアプリケーションの統計情報については下記コマンドで確認できます。

sh>>
roo> cloud foundry view app stats --appName cftestaka

============================== App. Stats ==============================

Instance CPU (Cores) Memory (limit) Disk (limit) Uptime


0 8.0 (4) 239.09M (256M) 28.0M (2048M) 0d:
<<--

さて、アプリケーションは起動しましたが、まだDBが使えるようになっていないので、Entityを操作するための画面に遷移しようとするとエラーになってしまいます。

まずはDBをサービスとして作成します。

sh>>
roo> cloud foundry create service --serviceName cftesakadb --serviceType postgresql
The service 'cftesakadb' was successfully created
<<--

サービスの一覧を確認すると、= Provisioned Services = の部分にサービスが追加になっています。

sh>>
roo> cloud foundry list services

======================= System Services ========================

Service Version Description


mysql 5.1 MySQL database service
postgresql 9.0 PostgreSQL database service (vFabric)
mongodb 1.8 MongoDB NoSQL store
redis 2.2 Redis key-value store service
rabbitmq 2.4 RabbitMQ messaging service

= Provisioned Services =

Name Service


cftesakadb postgresql
<<--

次に、作成したサービスをアプリケーションに紐付けます。

sh>>
roo> cloud foundry bind service --serviceName cftesakadb --appName cftestaka
The service 'cftesakadb' was successfully bound to the application 'cftestaka'
roo>
<<--

そしてアプリケーションを再起動します。

sh>>
roo> cloud foundry restart app --appName cftestaka
The application 'cftestaka' was successfully restarted
<<--

これでアプリケーションがDBを使えるようになり、EntityのCRUD画面も動作するようになります。

アプリケーションのログを確認するには下記コマンドを実行します。

sh>>
roo> cloud foundry view logs --appName cftestaka --instance 0
<<--

長いので出力は省略しますが、stderr.logとstdout.logが閲覧できます。

それと現在のメモリの割当量は下記コマンドで確認できます。

sh>>
roo> cloud foundry view app memory --appName cftestaka

= Application Memory =

Name Memory


cftestaka 256MB
<<--

現在は256MBのメモリが割り当てられています。この割当量を変更するには下記のようにコマンドを実行します。

sh>>
roo> cloud foundry update app memory --appName cftestaka --memSize 512MB

= Application Memory =

Name Memory


cftestaka 512MB
<<--

メモリ量が512MBに変更されました。

RooとCloud Foundryの組み合わせなら簡単なCRUDアプリの公開はとてもスピーディーに行うことができそうです。まだCloud Foundryはベータ版なので、正式版になったときに料金体系などがどうなるかは気になりますが、Roo + Cloud Foundryで何か公開できるようなサービスでも作れないかなぁと思っています。

posted by akanuma akanuma on Mon 12 Dec 2011 at 00:11 with 0 comments

 以前のエントリでProjectの作成まで書いたので、Entity作成についてのメモです。

以前のエントリはこちら

Spring Roo Install

[Spring Roo]プロジェクト作成, Logging&DB接続設定

  • roo shell上でentityコマンドを実行することでEntityが作成されます。下記はProjectというEntityを作成する例です。

sh>>
roo> entity --class ~.model.Project --testAutomatically
Created SRC_MAIN_JAVA\com\example\model
Created SRC_MAIN_JAVA\com\example\model\Project.java
Created SRC_TEST_JAVA\com\example\model
Created SRC_TEST_JAVA\com\example\model\ProjectDataOnDemand.java
Created SRC_TEST_JAVA\com\example\model\ProjectIntegrationTest.java
Created SRC_MAIN_JAVA\com\example\model\Project_Roo_Configurable.aj
Created SRC_MAIN_JAVA\com\example\model\Project_Roo_Entity.aj
Created SRC_MAIN_JAVA\com\example\model\Project_Roo_ToString.aj
Created SRC_TEST_JAVA\com\example\model\ProjectDataOnDemand_Roo_Configurable.aj
Created SRC_TEST_JAVA\com\example\model\ProjectDataOnDemand_Roo_DataOnDemand.aj
Created SRC_TEST_JAVA\com\example\model\ProjectIntegrationTest_Roo_Configurable.aj
Created SRC_TEST_JAVA\com\example\model\ProjectIntegrationTest_Roo_IntegrationTest.aj
<<--

  • com.exampleパッケージの下にmodelパッケージが作成され、その下にProjectクラス(Project.java)が作成されます。そしてそれに関連するjavaクラスファイル、AspectJのファイルやテストクラスが自動生成されます。

  • 続いてEntity内の各プロパティを追加していきます。Entity作成直後はそのEntityにフォーカスがあたっていますが、他のEntityの作業をしたあとなど、対象のEntityにフォーカスがあたっていない場合は、focusコマンドで対象のEntityにフォーカスを当てます。

sh>>
roo> focus --class ~.model.Project
<<--

  • チルダ(~)はベースのパッケージを表すので、ここではcom.exampleにあたります。roo shellのプロンプトが下記のようになっていればProject Entityにフォーカスがあたっています。

sh>>
~.model.Project roo>
<<--

  • プロパティの追加はfieldコマンドで行います。下記は文字列型のnameというプロパティを追加する例です。

sh>>
~.model.Project roo> field string --fieldName name
Updated SRC_MAIN_JAVA\com\example\model\Project.java
Created SRC_MAIN_JAVA\com\example\model\Project_Roo_JavaBean.aj
Updated SRC_TEST_JAVA\com\example\model\ProjectDataOnDemand_Roo_DataOnDemand.aj
Updated SRC_MAIN_JAVA\com\example\model\Project_Roo_ToString.aj
<<--

  • Project.javaがと関連するファイルが更新・作成されます。

  • プロパティに最大文字数やNull禁止の制約をつけたい場合には、プロパティ追加時に下記のようなオプションを追加します。

sh>>
~.model.Project roo> field string --fieldName name --notNull --sizeMax 30
Updated SRC_MAIN_JAVA\com\example\model\Project.java
Updated SRC_TEST_JAVA\com\example\model\ProjectDataOnDemand_Roo_DataOnDemand.aj
Created SRC_MAIN_JAVA\com\example\model\Project_Roo_JavaBean.aj
Updated SRC_MAIN_JAVA\com\example\model\Project_Roo_ToString.aj
<<--

  • 上記の例は最大文字数は30文字でNullは禁止する例です。

  • 数値型のプロパティを追加する場合には型としてnumberを指定し、--typeオプションでJavaのクラスを指定します。

sh>>
~.model.Project roo> field number --fieldName cnt --type java.lang.Integer
<<--

  • 日付型の場合もJavaのクラス名をあわせて指定します。

sh>>
~.model.Project roo> field date --fieldName createdTime --type java.util.Date
<<--

  • 他のクラスへの関連をプロパティとして持つには、fieldコマンドの型の指定でsetを指定し、--typeで対象のクラス、--cardinalityオプションで関連の持ち方、--mappedByオプションでもう一方のEntityからこのEntityを参照するためのフィールド名を指定します。下記はProject EntityがSubProject Entityへの関連を一対多で持つ例です。SubProject Entityからはprojectというフィールド名でProject Entityを参照します。

sh>>
~.model.Project roo> field set --fieldName subProjects --type ~.model.SubProject --cardinality ONE_TO_MANY --mappedBy project
<<--

  • 関連が多対一の場合には上記コマンドの--cardinalityをMANY_TO_ONEに、多対多の場合にはMANY_TO_MANYに変更します。

  • ここまでを必要なEntityとプロパティに対して実行すれば、アプリケーションの起動時に対応するテーブルがDBに作成されます。

posted by akanuma akanuma on Wed 30 Nov 2011 at 08:39 with 0 comments

前のエントリでRooのインストールが終わったので、プロジェクトを作成します。

  • まず作業ディレクトリを作成し、コマンドプロンプトを起動してそのディレクトリへ移動します。

  • roo shell を起動します。

sh>>

roo


/ __ / __ / __
/ // / / / / / / /
/ , / // / // /
/
/ ||_/__/ 1.1.5.RELEASE [rev d3a68c3]

Welcome to Spring Roo. For assistance press TAB or type "hint" then hit ENTER.
roo>
<<--

  • プロジェクトを作成します。projectコマンドの--topLevelPackageでベースとなるパッケージ名を指定します。生成されるクラスはこのパッケージの下に作成されることになります。--projectNameオプションではプロジェクト名を指定します。

sh>>
roo> project --topLevelPackage com.example --projectName example
Created ROOT\pom.xml
Created SRC_MAIN_JAVA
Created SRC_MAIN_RESOURCES
Created SRC_TEST_JAVA
Created SRC_TEST_RESOURCES
Created SRC_MAIN_WEBAPP
Created SRC_MAIN_RESOURCES\META-INF\spring
Created SRC_MAIN_RESOURCES\log4j.properties
Created SRC_MAIN_RESOURCES\META-INF\spring\applicationContext.xml
com.example roo>
<<--

  • ロギングのレベルをWARNに設定しておきます。loggingコマンドを実行することでlog4j.propertiesの内容が変更されます。

sh>>
com.example roo> logging setup --level WARN
Updated SRC_MAIN_RESOURCES\log4j.properties
com.example roo>
<<--

  • データベースの設定もしてしまいます。persistence setupでDBへの接続設定が作成されます。ここではPostgresqlとHibernateを使う設定です。

sh>>
com.example roo> persistence setup --provider HIBERNATE --database POSTGRES --userName appuser --password apppwd --databaseName example
Created SRC_MAIN_RESOURCES\META-INF\spring\database.properties
Please update your database details in src/main/resources/META-INF/spring/database.properties.
Updated ROOT\pom.xml [added dependencies postgresql:postgresql:8.4-702.jdbc3, org.hibernate:hibernate-core:3.6.4.Final,
org.hibernate:hibernate-entitymanager:3.6.4.Final, org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final, or
g.hibernate:hibernate-validator:4.1.0.Final, javax.validation:validation-api:1.0.0.GA, cglib:cglib-nodep:2.2, javax.tran
saction:jta:1.1, org.springframework:spring-jdbc:${spring.version}, org.springframework:spring-orm:${spring.version}, co
mmons-pool:commons-pool:1.5.4, commons-dbcp:commons-dbcp:1.3; added repository https://repository.jboss.org/nexus/conten
t/repositories/releases]
Updated SRC_MAIN_RESOURCES\META-INF\spring\applicationContext.xml
Created SRC_MAIN_RESOURCES\META-INF\persistence.xml
com.example roo>
<<--

  • database properties listコマンドで設定内容が確認できます。

sh>>
com.example roo> database properties list
database.driverClassName = org.postgresql.Driver
database.password = appuser
database.url = jdbc:postgresql://localhost:5432/example
database.username = apppwd
com.example roo>
<<--

  • デフォルトでは persistence.xml 内の hibernate.hbm2ddl.auto の値は create になっていますが、これだとアプリケーションを起動するたびにDBスキーマが再作成されてしまうので、エディタでpersistence.xmlを開いて update に変更しておきます。

  • これでひとまずアプリケーションのベースが作成されたので、次のエントリでEntityの作成について書きたいと思います。

posted by akanuma akanuma on Fri 18 Nov 2011 at 08:32 with 0 comments

仕事で Spring Roo を使う機会が増えてきたので、チュートリアル的な内容をメモ。まずはRooのインストールについてです。

Rooインストール

  • Spring Rooのサイト から下記ファイルをダウンロードします。

    ・spring-roo-1.1.5.RELEASE.zip

  • 解凍して任意のディレクトリに配置します。

  • 上記ディレクトリを環境変数 ROO_HOME に設定し、 %ROO_HOME%\bin を環境変数 PATH に追加します。

  • コマンドプロンプトから roo と入力して実行することで roo shell が起動します。

sh>>

roo


/ __ / __ / __
/ // / / / / / / /
/ , / // / // /
/
/ ||_/__/ 1.1.5.RELEASE [rev d3a68c3]

Welcome to Spring Roo. For assistance press TAB or type "hint" then hit ENTER.

At this time you have not authorized Spring Roo to download an index of
available add-ons. This will reduce Spring Roo features available to you.
Please type 'download status' and press ENTER for further information.

roo>
<<--

  • リソースのダウンロードに同意するために、download status と入力して実行します。

sh>>
roo> download status

**** DOWNLOAD CONSENT REQUIRED ****

Spring Roo needs to download resources from VMware domains to improve your
experience. We include anonymous usage information as part of these downloads.

The Spring team gathers anonymous usage information to improve your Spring
experience, not for marketing purposes. For example, we collect anonymous
information about the usage of public Roo add-ons. This lets us offer you
higher quality add-on search results, highlighting the add-ons which are most
popular in the Roo community. We also use this information to help guide our
roadmap, prioritizing the features most valued by the community and enabling
us to optimize the compatibility of technologies frequently used together.

Please see the Spring User Agent Analysis (UAA) Terms of Use at
http://www.springsource.org/uaa/terms_of_use for more information on what
information is collected and how such information is used. There is also an
FAQ at http://www.springsource.org/uaa/faq for your convenience.

To consent to the Terms of Use, please type 'download accept terms of use' at
the command prompt and press ENTER. If you do not type 'download accept terms
of use' to indicate your consent, Spring Roo add-on discovery features will
not be available and anonymous data collection will remain disabled.

Next steps:

  • To enable downloads, type 'download accept terms of use' and press ENTER

  • To disable downloads, type 'download reject terms of use' and press ENTER

If you don't type either command, Roo will remind you next time it loads.

roo>
<<--

  • download accept terms of use を実行することでリソースのダウンロードに同意できます。

sh>>
roo> download accept terms of use
Thank you. All Spring Roo download features have now been enabled.
<<--

  • roo shell ではhintコマンドを実行することで次にやるべきことのヒントが表示されます。

sh>>
roo> hint
Welcome to Roo! We hope you enjoy your stay!

Before you can use many features of Roo, you need to start a new project.

To do this, type 'project' (without the quotes) and then hit TAB.

Enter a --topLevelPackage like 'com.mycompany.projectname' (no quotes).
When you've finished completing your --topLevelPackage, press ENTER.
Your new project will then be created in the current working directory.

Note that Roo frequently allows the use of TAB, so press TAB regularly.
Once your project is created, type 'hint' and ENTER for the next suggestion.
You're also welcome to visit http://forum.springframework.org for Roo help.
<<--

  • roo shell の終了は quitコマンドです。

sh>>
roo> quit
<<--

  • これでひとまずRooを使う環境が作成できました。
posted by akanuma akanuma on Thu 17 Nov 2011 at 08:42 with 0 comments

Mahout In Actionのコードを実行するために、EclipseでMahoutの開発をする環境を作成してみました。

下記サイトを参考にさせていただきました。

mahout/レコメンドシステムの作り方

前提

  • Java, Maven, Eclipseがインストール済みであること

手順

  1. m2eclipseプラグインのインストール
  2. Maven Projectの作成
  3. M2_REPOの設定
  4. mahout-coreのdependency設定
  5. Javaクラスの作成

それぞれの手順の内容は下記のとおりです。

・m2eclipseプラグインのインストール

Eclipse上からMavenの操作ができるようにするために、m2eclipseというプラグインをインストールします。

Eclipse の Helpメニュー > Install New Software... で下記URLを指定してインストールします。

http://m2eclipse.sonatype.org/sites/m2e

インストール後にはEclipseの再起動が必要です。

・Maven Projectの作成

Eclipse の Fileメニュー > New > Other...

Maven > Maven Project を選択して Maven Project を作成します。

・M2_REPOの設定

MavenのローカルリポジトリのパスをM2_REPOという変数名で設定します。

Eclipse の Windowメニュー > Preferences

Java > Build Path > Classpath Variables

Newボタンをクリックして Name と Value を設定します。私の場合は下記の用に設定しました。

  • Name: M2_REPO
  • Value: /home/h-akanuma/.m2/repository

・mahout-coreのdependency設定

Mahout のライブラリを使用できるようにするために、mahout-core の dependency を設定します。pom.xml の に下記の内容を追加します。

xml>>

org.apache.mahout
mahout-core
0.5


org.slf4j
slf4j-jcl
1.6.0
test

<<--

追加後にworkspace内のプロジェクトのディレクトリで下記mvnコマンドを実行して、依存性の解決とソースコードをダウンロードしてEclipseから参照できるようにします。

sh>>
~/workspace/ml$ mvn eclipse:eclipse -DdownloadSources=true
<<--

・Javaクラスの作成

Mahout In Action のサンプルクラスを作成してみます。

java>>
public class RecommenderIntro {
public static void main(String[] args) throws Exception {
DataModel model = new FileDataModel (new File("/tmp/intro.csv"));
UserSimilarity similarity = new PearsonCorrelationSimilarity (model);
UserNeighborhood neighborhood = new NearestNUserNeighborhood (2, similarity, model);
Recommender recommender = new GenericUserBasedRecommender (model, neighborhood, similarity);
List recommendations = recommender.recommend(1, 1);
for (RecommendedItem recommendation : recommendations) {
System.out.println(recommendation);
}
}
}
<<--

Ctrl+Shift+O などでクラスパスを解決できればMahoutのライブラリが参照できているので環境としてはとりあえずOKです。

上記Javaクラス内で使用している intro.csv の内容は下記のとおりです。

csv>>
1,101,5.0
1,102,3.0
1,103,2.5

2,101,2.0
2,102,2.5
2,103,5.0
2,104,2.0

3,101,2.5
3,104,4.0
3,105,4.5
3,107,5.0

4,101,5.0
4,103,3.0
4,104,4.5
4,106,4.0

5,101,4.0
5,102,3.0
5,103,2.0
5,104,4.0
5,105,3.5
5,106,4.0
<<--

Javaクラスと同じパスに保存してEclipse上から実行すると下記のような結果が得られます。

sh>>
RecommendedItem[item:104, value:4.257081]
<<--

※初稿掲載時は実行時に「intro.csvが見つからないと言われてしまう」と書いていましたが、intro.csvをフルパスで /tmp/intro.csv と指定することで解決しました。

posted by akanuma akanuma on Sun 30 Oct 2011 at 10:48 with 0 comments

まずは以下からtarballを取ってきます。

あとは展開して以下を実行

pre>>
% JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home ./configure
% make

make install

<<--

あとは、
/usr/local/lib/libjtokyocabinet.jnilib
/Library/Java/Extensions にコピーします。

posted by genki genki on Fri 25 Mar 2011 at 09:19 with 0 comments

Ubuntu 10.04 では、JDKのデフォルトが SunJDK から OpenJDK に変更され、SunJDK はパッケージにも含まれなくなりました。
恐らく、今後の Sun によるサポートを不安視する声が多く、
将来的に安定したパッケージリリースを行うために独立する流れになったのだと思われます。

しかしながら、OpenJDKは若干機能的にSunJDKに遅れている事もあり、
SunJDKが使えないと困る局面があるのも事実です。
その場合、以下のpartnerパッケージを追加することで、
10.04でもSunJDKが利用できるようです。

shell>>
deb http://archive.canonical.com/ lucid partner
<<--

shell>>

aptitude update

aptitude search sun-java6

p ia32-sun-java6-bin ...
p sun-java6-bin ...

aptitude install sun-java6-jdk

<<--

また、OpenJDKと併用している場合は、
下記でパッケージのデフォルト設定を SunJDK にすることが可能です。

shell>>

update-alternatives --config java

<<--

posted by maiha maiha on Thu 27 May 2010 at 14:16 with 0 comments

嫌がらせとしか思えないのですが、MacOSのJDK6は、デフォルトのエンコーディングがSJISになっています。JDK5ではUTF8だったのに、なぜ...

とりあえず、デフォルトでUTF8にしたい場合は、~/.zshrc あたりで

pre>>
export _JAVA_OPTIONS=-Dfile.encoding=UTF-8
<<--

しておけばok. 嵌りかけました。

posted by genki genki on Wed 26 May 2010 at 19:05 with 0 comments

I shipped new dm-datastore-adapter today.

This update is a long jump from previous version. It includes following functions

  • Transaction. It utilizes the DataStore's Transaction API
  • OR conditions
    ruby>>
    Post.all(:id => [1,2])
    <<--
  • NOT conditions
    ruby>>
    Post.all(:id.not => 4)
    <<--

So now we can use most of functions defined in DM by using this adapter.

Enjoy!

posted by takiuchi takiuchi on Fri 17 Apr 2009 at 05:44 with 0 comments

Today I shipped a new DataMapper plugin that enables us to easily develop Merb-apps been worked with GAE/J.

By using this plugin, you can seamlessly develop your Merb-apps between local and GAE/J environment.

For example, this site is powered by Merb/DM with the dm-datastore-adapter and running on the GAE/J

(This service is under construction :-p)

As a matter of fact, because it is still being alpha status,
you must treat various issues regarding gem dependencies yet.
I appreciate any kind of feedback and of course patches :-)

Enjoy!

posted by takiuchi takiuchi on Mon 13 Apr 2009 at 05:43 with 11 comments

DataMapper用のDataStore用アダプタ、dm-datastore-adapterを作りました。

これを使えば、MerbアプリをほぼそのままGoogle App Engine for Javaの上で動かせるようになります。
(実際にはgemの依存関係など、細かい調整が必要になりますが)

実際に以下のサイトでdm-datastore-adapterを使っています。

ローカル環境でも別なアダプタを利用すれば、普通のMerbアプリとして動作テストできるので、開発効率が飛躍的に向上します。

posted by genki genki on Mon 13 Apr 2009 at 05:37 with 0 comments