May 31, 2006
[Misc] 攻撃?? 研究?? 調査??
ありがちな脆弱性をねらったアクセスが来ていた。 Perl などで発生しやすい OS コマンドインジェクションを狙ったもの。
- HotFix Report - OSコマンド・インジェクション(OS command injection)
- http://www.hotfix.jp/archives/word/2004/word04-18.html
- セキュリティガイドライン - 4. OSコマンドインジェクション
- http://www.e-3lab.com/security_guideline/index.html#os
********************** - - [30/May/2006:10:56:18 +0900] "GET /blog/index.cgi/Web
Service/20051218_01.htm|ls%20-la| HTTP/1.1" 200 5857 "-" "Mozilla/4.0 (compatibl
e; MSIE 6.0; Windows NT 5.1)"
アクセス元が某国内有名研究所関連の組織なので、さすがにクラックするつもりではないと思うけれど。
調査・研究目的であっても、外部サーバに対して脆弱性を突く(可能性のある) URL を流すなら事前に教えて欲しい。
攻撃なのか調査・研究なのかはアクセスされた方では判断できないから。
・・・と個人的には思うが、人によって判断の分かれるところだろう。 面倒で一々連絡していられるか、ということかもしれない(^^;
とりあえず、怖いので攻撃は勘弁してくださいませ m(_ _)m > ALL
May 30, 2006
[Trac] Trac にチャレンジ(2)
Trac の動作環境が整ったので、実際に使用できるようにプロジェクトの初期設定を行う。 プロジェクトにはコンポーネントやマイルストーンなどの初期値が設定されている。 初期値をそのまま使うことはないので、初期値を削除して実際に使用する値をセットする。 この作業はコマンドラインから trac-admin コマンドを実行して行う。
component の設定
コンポーネントの初期値は component1, component2 となっている。 さすがに component1 という名前のコンポーネントを作成することはないだろう。 ということで、これを削除して新しいコンポーネントを追加する。
# trac-admin /tmp/trac/myprojects component list Name Owner -------------------- component1 somebody component2 somebody # trac-admin /tmp/trac/myprojects component remove component1 # trac-admin /tmp/trac/myprojects component remove component2 # trac-admin /tmp/trac/myprojects component list Name Owner ----------- # trac-admin /tmp/trac/myprojects component add MyComponent me # trac-admin /tmp/trac/myprojects component list Name Owner --------------------- MyComponent me #
version の設定
# trac-admin /tmp/trac/myprojects version list Name Time ---------- 1.0 2.0 # trac-admin /tmp/trac/myprojects version remove 1.0 # trac-admin /tmp/trac/myprojects version remove 2.0 # trac-admin /tmp/trac/myprojects version list Name Time ---------- # trac-admin /tmp/trac/myprojects version add 1.0.0 # trac-admin /tmp/trac/myprojects version list Name Time ----------- 1.0.0 #
milestone の設定
# trac-admin /tmp/trac/myprojects milestone list Name Time ---------------- milestone1 milestone2 milestone3 milestone4 # trac-admin /tmp/trac/myprojects milestone remove milestone1 # trac-admin /tmp/trac/myprojects milestone remove milestone2 # trac-admin /tmp/trac/myprojects milestone remove milestone3 # trac-admin /tmp/trac/myprojects milestone remove milestone4 # trac-admin /tmp/trac/myprojects milestone list Name Time ---------- #
May 29, 2006
[Trac] Trac にチャレンジ
Trac とは
Trac は Web インターフェースの Wiki + BugTracker + Subversion Viewer。 聞くところによると結構便利らしい。 WebSVN をインストールしようかと思っていたのだけれど、どうせなら BugTracker も一緒に欲しいということで Trac にしてみた。
- Trac
- http://www.edgewall.com/trac/
- The Trac Configuration File
- http://projects.edgewall.com/trac/wiki/TracIni
Trac のインストールや設定は以下のサイトを参考にさせていただいた。多謝。 (参考というより、指示通りに作業しただけ・・・)
- 鷹の島 - Trac をインストールしてみたよ
- http://espion.just-size.jp/archives/05/297225719.html
- [trac] default_charset
- http://zippo.taiyo.co.jp/~gotoh/diary/?200502a&to=200502023#200502023
Trac のインストール
Trac を Debian Sarge にインストールしたときのメモ。 Debian では apt で Trac をインストールできる。便利。 Trac 本体と Python でマルチバイトを扱うライブラリをインストールする。
# apt-get install trac Reading Package Lists... Done Building Dependency Tree... Done The following extra packages will be installed: libsqlite0 python python-clearsilver python-sqlite python2.3 python2.3-clearsilver python2.3-sqlite python2.3-subversion Suggested packages: python-doc python-tk python-profiler python2.3-doc python2.3-profiler enscript python-docutils Recommended packages: python2.3-iconvcodec python2.3-cjkcodecs python2.3-japanese-codecs python-egenix-mxdatetime The following NEW packages will be installed: libsqlite0 python python-clearsilver python-sqlite python2.3 python2.3-clearsilver python2.3-sqlite python2.3-subversion trac 0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded. Need to get 4654kB of archives. After unpacking 15.7MB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://www.jp.debian.org sarge/main libsqlite0 2.8.16-1 [176kB] Get:2 http://www.jp.debian.org sarge/main python2.3 2.3.5-3sarge1 [2906kB] Get:3 http://www.jp.debian.org sarge/main python 2.3.5-2 [127kB] Get:4 http://www.jp.debian.org sarge/main python2.3-clearsilver 0.9.13-3.2 [81.0kB] Get:5 http://www.jp.debian.org sarge/main python-clearsilver 0.9.13-3.2 [4820B] Get:6 http://www.jp.debian.org sarge/main python2.3-sqlite 1.0.1-2 [29.1kB] Get:7 http://www.jp.debian.org sarge/main python-sqlite 1.0.1-2 [2608B] Get:8 http://www.jp.debian.org sarge/main python2.3-subversion 1.1.4-2 [1130kB] Get:9 http://www.jp.debian.org sarge/main trac 0.8.1-3sarge4 [199kB] Fetched 4654kB in 22s (209kB/s) Preconfiguring packages ... ...略 # apt-get install python2.3-japanese-codecs Reading Package Lists... Done Building Dependency Tree... Done The following NEW packages will be installed: python2.3-japanese-codecs 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 273kB of archives. After unpacking 1237kB of additional disk space will be used. Get:1 http://www.jp.debian.org sarge/main python2.3-japanese-codecs 1.4.9-3 [273kB] Fetched 273kB in 1s (241kB/s) Selecting previously deselected package python2.3-japanese-codecs. (Reading database ... 15287 files and directories currently installed.) Unpacking python2.3-japanese-codecs (from .../python2.3-japanese-codecs_1.4.9-3_i386.deb) ... Setting up python2.3-japanese-codecs (1.4.9-3) ... #
Trac の設定
Trac プロジェクトの作成
# mkdir /tmp/trac # cd /tmp/trac # trac-admin myprojects initenv Creating a new Trac environment at /tmp/trac/myprojects Trac will first ask a few questions about your environment in order to initalize and prepare the project database. Please enter the name of your project. This name will be used in page titles and descriptions. Project Name [My Project]> my projects Please specify the absolute path to the project Subversion repository. Repository must be local, and trac-admin requires read+write permission to initialize the Trac database. Path to repository [/var/svn/test]> /var/svn/svndb Please enter location of Trac page templates. Default is the location of the site-wide templates installed with Trac. Templates directory [/usr/share/trac/templates]> Creating and Initializing Project Inserting default data Configuring Project trac.repository_dir ...略 Congratulations! # chown -R www-data:www-data /tmp/trac
Trac と Apache2 の連携
私の環境では、Trac のメインの用途は Subversion に対する Web インターフェースとなる。 そのため、Trac も Subversion と同一のユーザを使用することにした。 また、アクセス元制限もついでにかけておくことに。
# cat /etc/apache2/sites-available/trac Alias /trac "/usr/share/trac/htdocs/" ScriptAlias /proj "/usr/share/trac/cgi-bin/trac.cgi" <Location "/proj"> SetEnv TRAC_ENV "/tmp/trac/myprojects" SSLRequireSSL AuthType Basic AuthName "please login" AuthUserFile /var/svn/svndb/.svnpasswd Require valid-user order allow,deny allow from 192.168.1. </Location> <Location "/trac"> SSLRequireSSL AuthType Basic AuthName "please login" AuthUserFile /var/svn/svndb/.svnpasswd Require valid-user order allow,deny allow from 192.168.1. </Location> # a2ensite trac Site trac installed; run /etc/init.d/apache2 reload to enable. # /etc/init.d/apache2 reload Reloading web server config...done.cts" #
Trac の設定
Trac 画面のヘッダ、フッタを設定する。 Subversion 内のファイルの文字エンコーディングも設定する。
# cat /tmp/trac/myprojects/conf/trac.ini [header_logo] src = trac_banner.png alt = my projects height = 73 link = https://www.example.com/proj width = 236 [trac] default_charset = japanese.shift_jis ...略 #
May 28, 2006
[Library] JasperReports にチャレンジ
JasperReports とは
JasperReports はオープンソースの帳票ソリューション。 帳票印刷、PDF 生成はもちろんのこと、HTML、XLS、CSV、XML の生成が可能。 帳票のデザイナもオープンソースで提供されている、なかなかの優れもの。
- JasperReports
- http://jasperreports.sourceforge.net/index.html
- Tutorial
- http://jasperreports.sourceforge.net/tutorial/index.html
- GUI Tools
- http://jasperreports.sourceforge.net/tools.html
- License
- http://jasperreports.sourceforge.net/license.html
サンプル実行
実行環境準備
サンプルの実行には JDK、Ant が必要。
>set JAVA_HOME=c:\_java\jdk\1.5.0_06 >set ANT_HOME=c:\_java\tool\ant\1.6.4 >set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;%PATH% >java -version java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05) Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing) >ant -version Apache Ant version 1.6.4 compiled on May 19 2005 >cd .\jasperreports-1.2.2\demo\samples\csvdatasource
csvdatasource サンプルの実行
>ant clean javac compile fill pdf
Buildfile: build.xml
clean:
javac:
[javac] Compiling 1 source file to C:\jasperreports-1.2.2\demo\samples\csvda
tasource
[javac] 注: C:\jasperreports-1.2.2\demo\samples\csvdatasource\CsvDataSourceA
pp.java の操作は、未チェ
ックまたは安全ではありません。
[javac] 注: 詳細については、-Xlint:unchecked オプションを指定して再コンパイ
ルしてください。
compile:
[jrc] Compiling 1 report design files.
[jrc] File : C:\jasperreports-1.2.2\demo\samples\csvdatasource\CsvDataSourc
eReport.jrxml ... OK.
fill:
[java] Filling time : 1641
pdf:
[java] PDF creation time : 1312
BUILD SUCCESSFUL
Total time: 8 seconds
fonts サンプルの実行
>ant clean javac compile fill pdf
Buildfile: build.xml
clean:
javac:
[javac] Compiling 1 source file to C:\jasperreports-1.2.2\demo\samples\fonts
[javac] 注: C:\jasperreports-1.2.2\demo\samples\fonts\FontsApp.java の操作は
、未チェックまたは安全ではありません。
[javac] 注: 詳細については、-Xlint:unchecked オプションを指定して再コンパイ
ルしてください。
compile:
[jrc] Compiling 1 report design files.
[jrc] File : C:\jasperreports-1.2.2\demo\samples\fonts\FontsReport.jrxml .
.. OK.
fill:
[java] Filling time : 2187
pdf:
[java] PDF creation time : 2250
BUILD SUCCESSFUL
Total time: 10 seconds
May 27, 2006
[Maven] pom.xml で entity reference が使えない理由
pom.xml では entity reference が使用できない。 使えないのは実際に試した結果から知っていたが、理由が分からなかった。 ようやく使えない理由が書かれたドキュメントを見つけたのでメモ。 Maven 1.x の FAQ なのだけれど、Maven 2.x でも同様の理由で使えなくなっているのだろう。 使えると非常に便利なのだけれど、機構的に仕方がないといったところか。
- Apache Maven 1.x Frequently Asked Questions
- http://maven.apache.org/maven-1.x/faq.html#using-entities
Q. What's the problem with entities in project.xml?
A. As of Maven 1.1, external entities will not be enabled by default in project.xml, and their use is discouraged in Maven 1.0.x as well. There will still be the ability to use them, but it will have to be enabled.
There are several reasons for this, but the main reason is that the content of project.xml needs to be completely self-contained and and able to be reproduced from a history at any point in time.
For this reason, using Jelly expressions other than ${pom.*} references is also not recommended and likely to be unsupported in future.
The most common use of this technique is to manage dependencies across multiple projects. You should strongly consider using inheritence for this purpose.
Note: special character entities will always be supported and should not have any current issues.
May 26, 2006
[Maven] Maven2 のバージョンを自動チェックする方法
Maven2 の実行時に Maven2 のバージョンを自動チェックすることができる。 例えば、2.0.3 以前の Maven2 が使用された場合はビルドを強制的に失敗させる、といったことが可能。 ビルドプロセスが Maven2 のバージョンに依存することは少ないと思うけれど、大規模プロジェクトではこの機能を使っておくと安心できそう。
設定方法
pom.xml の project/prerequisites/maven でバージョンを指定する。
詳細な設定方法は以下を参照のこと。<project> <prerequisites> <maven>2.0.4</maven> </prerequisites> </project>
- Project Descriptor - Prerequisites
- http://maven.apache.org/ref/current/maven-model/maven.html#class_prerequisites
動作例
project/prerequisites/maven に 2.0.5 を指定した状態で、2.0.4 を使用してビルドすると下記の様にビルドに失敗する。
>mvn --version Maven version: 2.0.4 >mvn clean [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [ERROR] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Unable to build project 'C:\MyProject\pom.xml; it requires Maven version 2.0.5 [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: < 1 second [INFO] Finished at: Thu May 25 19:09:36 JST 2006 [INFO] Final Memory: 1M/2M [INFO] ------------------------------------------------------------------------
May 25, 2006
[Misc] 公開サーバに用意すべきメールアドレス
公開サーバで用意すべきメールアドレスが RFC2142 で規定されている。
- RFC2142 - MAILBOX NAMES FOR COMMON SERVICES, ROLES AND FUNCTIONS
- http://www.ietf.org/rfc/rfc2142.txt
- RFC2142 - 一般的なサービス、役割、機能に対するメールボックス名
- http://rfc-jp.nic.ad.jp/rfc-jp/RFC2142-JP.txt
RFC 2142 で規定されているメールアドレス
RFC 2142 ではビジネス関連、ネットワーク運用関連、インターネットサービス関連の 3 種類のメールアドレスが規定されている。
BUSINESS-RELATED MAILBOX NAMES
MAILBOX AREA USAGE
----------- ---------------- ---------------------------
INFO Marketing Packaged information about the
organization, products, and/or
services, as appropriate
MARKETING Marketing Product marketing and
marketing communications
SALES Sales Product purchase information
SUPPORT Customer Service Problems with product or
service
NETWORK OPERATIONS MAILBOX NAMES MAILBOX AREA USAGE ----------- ---------------- --------------------------- ABUSE Customer Relations Inappropriate public behaviour NOC Network Operations Network infrastructure SECURITY Network Security Security bulletins or queries
SUPPORT MAILBOX NAMES FOR SPECIFIC INTERNET SERVICES MAILBOX SERVICE SPECIFICATIONS ----------- ---------------- --------------------------- POSTMASTER SMTP [RFC821], [RFC822] HOSTMASTER DNS [RFC1033-RFC1035] USENET NNTP [RFC977] NEWS NNTP Synonym for USENET WEBMASTER HTTP [RFC 2068] WWW HTTP Synonym for WEBMASTER UUCP UUCP [RFC976] FTP FTP [RFC959]
要するに
自宅サーバの様な小規模公開サイトの場合、POSTMASTER、HOSTMASTER、WEBMASTER、WWW を用意すればよさそう。 ビジネス関連のサービスを提供する場合は更に INFO、MARKETING、SALES、SUPPORT も必要か。
May 24, 2006
[Misc] 開発環境における環境変数の設定
Windows における環境変数にはスコープの違いによりシステム環境変数、ユーザ環境変数、一時的な環境変数の 3 種類の環境変数がある。
- システム環境変数
- システムのすべてのユーザーに適用される環境変数
- ユーザ環境変数
- それぞれのユーザーごとに異なる環境変数
- 一時的な環境変数
- 特定の CMD プロセス内でのみ有効な環境変数
環境変数の設定指針
チームメンバへの説明をするときのために設定指針をまとめておく。
1. システム環境変数を変更しない
特にパスやパスに類する環境変数(JAVA_HOMEなど)はシステム環境変数として設定すべきではない。 システム環境変数は新規にソフトウェアをインストールする際に、インストーラに変更されてしまうことがあることを考慮しないといけない。 例えば、Oracle Database Server をインストールするとシステム環境変数の PATH の先頭に Oracle 内の JDK が追加されてしまう。
2. ユーザ環境変数を変更しない
こちらもシステム環境変数と同様。
3. 環境変数はバッチファイルで設定する
別に CMD 起動後に毎回手で打っても良いのだけれど、バッチファイルの方が間違いがないのと面倒がないのでオススメ。
4. パスを追加する際は既存のパスの先頭に追加する
言わずもがな。 既存のパスの後ろに追加する人にはさすがに出会ったことはないが、念のため。
> set JAVA_HOME=c:\_java\jdk\1.6.0 > set ANT_HOME=c:\_java\tool\ant\1.6.5 > set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;%PATH%
5. パスを追加する際は、追加後に必ずバージョンを確認する
パスを変更したら、必ず使用する前にバージョンを確認すること。 先頭に追加すればまず間違いは無いが、設定をミスしていると予期しないバージョンのものを使用してしまっている可能性がある。 プロジェクトでは通常使用するソフトウェアのバージョンが規定されている。 自分が使用しているソフトウェアのバージョンくらいはきちんと把握しておいて欲しい。 少なくとも JDK、JRE のバージョンくらいは・・・。
> set JAVA_HOME=c:\_java\jdk\1.6.0 > set PATH=%JAVA_HOME%\bin;%PATH% > java -version java version "1.6.0-beta" Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-beta-b59g) Java HotSpot(TM) Client VM (build 1.6.0-beta-b59g, mixed mode, sharing)
May 23, 2006
[Misc] DOS Command に関する参考資料をメモ
私より下の世代の人は DOS に関する知識を余り持っていないことが多い。 本番環境として Windows を使用することは少ないにしても、開発は Windows でやることが多いのだから最低限は知っておいて欲しいところ。 今更 config.sys を書けとは言わないが、バッチファイルは書けないと困る。 というわけで、DOS Command に関する参考資料をメモ。
- New ways to do familiar tasks
- http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/dos_diffs.mspx
- New command-line tools
- http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_new_tools.mspx
- Command-line reference A-Z
- http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx
- Batch Commands
- http://www.microsoft.com/technet/archive/msdos/07_refer.mspx
May 22, 2006
[Misc] JMX の参考資料をメモ
JBoss AS のソースコードを読み始めて、Microkernel で苦しんでいる。 JMX の詳細を把握していないのが原因。 ということで、JMX の参考資料をメモ。
- JMX
- http://java.sun.com/products/JavaManagement/index.jsp
- JMX Downloads
- http://java.sun.com/products/JavaManagement/download.html
- Sun Community Source Licensing (SCSL) - Java(TM) Management Extensions (JMX) - Download
- http://www.sun.com/software/communitysource/jmx/download.xml
- JSR 255: JavaTM Management Extensions (JMXTM) Specification, version 2.0
- http://jcp.org/en/jsr/detail?id=255
- JSR-000003 Java Management Extensions (JMX) (Maintenance Release 2)
- http://jcp.org/aboutJava/communityprocess/final/jsr003/index3.html
- Wikipedia - Java Management Extensions
- http://en.wikipedia.org/wiki/Java_Management_Extensions
- JBoss Architecture Overview
- http://jboss.com/products/jbossas/architecture
- Apache Geronimo Architecture
- http://wiki.apache.org/geronimo/Architecture
May 21, 2006
[Subversion] CentOS 4.x に Subversion をインストールする方法
CentOS 4.x に Subversion をインストールしたときのメモ。 apt の代わりに yum を使用するだけで、基本的には Debian と同じ。
Subversion のインストール手順
インストール先 CentOS のバージョンは以下の通り。
インストール作業自体は yum を使用するだけで完了する。# cat /etc/redhat-release CentOS release 4.2 (Final)
Apache2 と連携するために mod_dav_svn もインストールしておく。# yum install subversion ============================================================================= Package Arch Version Repository Size ============================================================================= Installing: subversion i386 1.1.4-2.ent base 1.6 M Installing for dependencies: neon i386 0.24.7-4 base 86 k
後は Subversion の設定ファイルを適当にいじれば OK。 設定ファイルは Debian とは異なり /etc/httpd/conf.d/subversion.conf にある。# yum install mod_dav_svn ============================================================================= Package Arch Version Repository Size ============================================================================= Installing: mod_dav_svn i386 1.1.4-2.ent base 50 k
May 20, 2006
[Misc] MySQL の文字エンコーディング関連設定
Windows で開発して Linux で稼働させる、といった状況だと文字エンコーディングは UCS2 や UTF-8 にしておくと楽。 MySQL を UTF-8 で動作させるための設定方法をメモしておく。
- 4.1.2. my.cnf オプション設定ファイル
- http://dev.mysql.com/doc/refman/4.1/ja/option-files.html
- 付録 F. 環境変数
- http://dev.mysql.com/doc/refman/4.1/ja/environment-variables.html
- 9.3.6. 接続のキャラクタセットおよび照合順序
- http://dev.mysql.com/doc/refman/4.1/ja/charset-connection.html
- ぱんぴーまっしぐら - PHPとMySQLの個人的まとめ
- http://puchiko.lowtech.ne.jp/?itemid=349&catid=27
設定方法
環境変数を毎回指定しても良いが、/etc/my.cnf を編集すると毎回毎回の手間を省くことができる。
現在の文字エンコーディング関連設定がどうなっているのかを調べる方法は以下の通り。# cat /etc/my.cnf [mysql] default-character-set=utf8 [mysqld] default-character-set=utf8 character_set_server=utf8
使用した環境は以下の通り。# mysql -u mysqlaccount -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 141 to server version: 4.1.12 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> SHOW VARIABLES LIKE 'character\_set\_%'; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | +--------------------------+-------+ 6 rows in set (0.00 sec)
# mysqladmin -u mysqlaccount -p version Enter password: mysqladmin Ver 8.41 Distrib 4.1.12, for redhat-linux-gnu on i686 Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL license Server version 4.1.12 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 1 hour 31 min 52 sec Threads: 2 Questions: 2227 Slow queries: 0 Opens: 97 Flush tables: 1 Open tables: 64 Queries per second avg: 0.404
May 18, 2006
[Library] Java Plugin Framework(JPF) にチャレンジ(2)
Plugin の構成
Plugin のディレクトリ構成は以下の通り。 このディレクトリ構成を ZIP、JAR でアーカイブ化すると Plugin になる。
PLUGIN_HOME ├classes/ ├docs/ │ └api/ ├icons/ ├lib/ └plugin.xml
plugin.xml の DTD は以下にある。
- Plug-in DTD
- http://jpf.sourceforge.net/dtd.html
May 17, 2006
[Library] Java Plugin Framework(JPF) にチャレンジ
Java Plugin Framework(JPF) とは
JPF は、Plugin アーキテクチャをサポートするためのライブラリ。 ZIP や JAR 形式で Plugin を作成し、アプリケーションからその Plugin を読み込み利用する。
- Java Plugin Framework(JPF)
- http://jpf.sourceforge.net/
- Tutorial
- http://jpf.sourceforge.net/tutorial.html
デモアプリケーションの起動
JPF にはデモアプリケーションが用意されている。 デモアプリケーションは簡単に起動し、Plugin のロードを試すことができる。
jpf-demo-bin-0.8> set JAVA_HOME=c:\_java\jdk\1.5.0_06 jpf-demo-bin-0.8> set PATH=%JAVA_HOME%\bin;%PATH% jpf-demo-bin-0.8> run.bat
サンプルコード
PluginManager を初期化し、Plugin をロードするサンプルコード。
package jp.in_vitro.codelets.jpf;
import java.io.InputStream;
import java.util.Collection;
import org.java.plugin.ObjectFactory;
import org.java.plugin.PluginManager;
import org.java.plugin.PluginManager.PluginLocation;
import org.java.plugin.boot.DefaultPluginsCollector;
import org.java.plugin.boot.PluginsCollector;
import org.java.plugin.registry.ExtensionPoint;
import org.java.plugin.registry.PluginDescriptor;
import org.java.plugin.util.ExtendedProperties;
public class Codelet {
public Codelet() {
super();
}
protected void execute() throws Exception {
ExtendedProperties config = new ExtendedProperties(System
.getProperties());
InputStream is = null;
try {
String configFile = "/"
+ this.getClass().getPackage().getName().replaceAll("\\.",
"/") + "/" + "config.properties";
is = this.getClass().getResourceAsStream(configFile);
config.load(is);
} finally {
if (is != null) {
is.close();
}
}
PluginManager pluginManager = ObjectFactory.newInstance(config)
.createManager();
PluginsCollector collector = new DefaultPluginsCollector();
collector.configure(config);
Collection pluginLocations = collector.collectPluginLocations();
pluginManager.publishPlugins((PluginLocation[]) pluginLocations
.toArray(new PluginLocation[pluginLocations.size()]));
for (Object pdObj : pluginManager.getRegistry().getPluginDescriptors()) {
PluginDescriptor pd = (PluginDescriptor) pdObj;
System.out.println("" + pd);
for (Object epObj : pd.getExtensionPoints()) {
ExtensionPoint ep = (ExtensionPoint) epObj;
System.out.println(" " + ep);
}
}
}
public static void main(String[] args) throws Exception {
Codelet me = new Codelet();
me.execute();
}
}
config.properties
org.java.plugin.PathResolver=org.java.plugin.standard.ShadingPathResolver
org.java.plugin.standard.ShadingPathResolver.shadowFolder=${applicationRoot}/temp/.jpf-shadow
org.java.plugin.standard.ShadingPathResolver.unpackMode=smart
org.java.plugin.boot.pluginsRepositories=./plugins/
サンプルコードの実行結果
plugins ディレクトリにデモアプリケーションの Plugin をいくつか登録して読み込ませてみた。
2006/05/16 23:58:37 org.java.plugin.registry.xml.ManifestParser情報: got SAX parser factory - com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl@16a55fa 2006/05/16 23:58:37 org.java.plugin.registry.xml.PluginRegistryImpl configure 情報: configured, stopOnError=false, isValidating=true 2006/05/16 23:58:37 org.java.plugin.standard.ShadingPathResolver configure 情報: configured, shadow folder is C:\Codelets\${applicationRoot}\temp\.jpf-shadow 2006/05/16 23:58:37 org.java.plugin.registry.xml.PluginRegistryImpl register 情報: plug-in and fragment descriptors registered - 2 {PluginDescriptor: uid=org.jpf.demo.toolbox.pluginbrowser@0.0.4} {PluginDescriptor: uid=org.jpf.demo.toolbox.core@0.0.4} {ExtensionPoint: uid=org.jpf.demo.toolbox.core@Tool}
May 15, 2006
[Misc] ClassLoader に関する参考資料をメモ
未だに ClassLoader を実装するとハマることがある。 何年実装やっているんだ・・・orz というわけで、ClassLoader に関する再勉強の必要性を強く感じて参考資料を集めてみた。
- JSR 924: Java Virtual Machine Specification
- http://www.jcp.org/en/jsr/detail?id=924
- The Java Virtual Machine Specification Second Edition
- http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html
- Java2 Platform SE 5.0 API Document - java.lang.ClassLoader
- http://java.sun.com/j2se/1.5.0/ja/docs/ja/api/java/lang/ClassLoader.html
- The Apache Tomcat 5.5 Servlet/JSP Container Class Loader HOW-TO
- http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
- developerWorks - クラス・ローディングとデバッグ・ツール
- http://www-06.ibm.com/jp/developerworks/java/060113/j_j-dclp1.shtml
- developerWorks - クラス・ローディングに関する基本的な例外
- http://www-06.ibm.com/jp/developerworks/java/060127/j_j-dclp2.shtml
ちなみに、今回ハマった状況はこういうもの。
「class A extends B」というクラスをロードする。
B をシステム ClassLoader がロード、A を自作 ClassLoader がロード。
特定環境下で 「A.class.getSuperclass」 が何故か java.lang.Object を返してくるという問題が発生。
結局のところ、ClassLoader の階層構造にミスがあったのだけれど、発生する環境としない環境があって結構手こずった。
教訓 - ClassLoader の階層構造はきちんと把握しよう。
May 14, 2006
[Misc] JSTL に関する参考資料をメモ
JSTL に関するサイトをメモ。
- JSTL 1.1 API Document
- http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/index.html
- JavaServer Pages Standard Tag Library
- http://java.sun.com/products/jsp/jstl/index.jsp
- JSR 052 JavaServer Pages Standard Tag Library Specification
- http://jcp.org/aboutJava/communityprocess/final/jsr052/
- developerWorks - JSTL入門: 式言語
- http://www-06.ibm.com/jp/developerworks/java/030411/j_j-jstl0211.html
- developerWorks - JSTL入門: 核心(core)に触れる
- http://www-06.ibm.com/jp/developerworks/java/030516/j_j-jstl0318.html
May 13, 2006
[Misc] 日本固有のバリデーションに関わる資料をメモ。
日本固有のバリデーションに関する資料をメモ。 海外製ライブラリは当然の様にこの辺りは未サポート。 自前のライブラリを「正確に」作成する場合に参照すると良いページ。
- ゆうびんホームページ - 郵便番号検索
- http://www.post.japanpost.jp/zipcode/
- 全国地方公共団体コード
- http://ja.wikipedia.org/wiki/%E5%85%A8%E5%9B%BD%E5%9C%B0%E6%96%B9%E5%85%AC%E5%85%B1%E5%9B%A3%E4%BD%93%E3%82%B3%E3%83%BC%E3%83%89
- JIS X 0401 都道府県コード
- http://www.webstore.jsa.or.jp/webstore/Com/FlowControl.jsp?lang=jp&bunsyoId=JIS+X+0401%3A1973&dantaiCd=JIS&status=1&pageNo=0
- JIS X 0402 市区町村コード
- http://www.webstore.jsa.or.jp/webstore/Com/FlowControl.jsp?lang=jp&bunsyoId=JIS+X+0402%3A2003&dantaiCd=JIS&status=1&pageNo=0
- 市外局番の一覧
- http://www.soumu.go.jp/joho_tsusin/top/tel_number/shigai_list.html
May 12, 2006
[Library] Eclipse 3.1 で JUnit 4 のテストケースを一括実行する
JUnit 4 は JUnit 3 よりも楽にテストケースを作成できる。 最近はめっきり JUnit 4 に染まってしまった。 ただ、ツールのサポートが追いついていないところだけが玉に瑕。 Eclipse 3.1 の環境下で、JUnit 4 のテストケースを一括実行したいので簡単なコードを書いてみた。
JUnit 4 のテストケース一括実行用クラス
↓のコード (AllTests) をプロジェクトのルートパッケージに置いて実行する。 AllTests が置いてあるパッケージ以下の全テストケース("**/*Test.class") が実行される。 JVM は 5.0 以降が必要。
package jp.in_vitro.test;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import junit.framework.TestSuite;
public class AllTests {
public static Test suite() throws URISyntaxException,
ClassNotFoundException {
return AllTests.createTestSuite();
}
protected static TestSuite createTestSuite() throws URISyntaxException,
ClassNotFoundException {
TestSuite suite = new TestSuite();
URL codeSourceUrl = AllTests.class.getProtectionDomain()
.getCodeSource().getLocation();
File codeSourceFile = new File(codeSourceUrl.toURI());
String codeSourceName = codeSourceFile.getAbsolutePath().replaceAll(
"\\\\", "\\\\\\\\");
List<File> testCaseFiles = new ArrayList<File>();
AllTests.listTestCase(testCaseFiles, codeSourceFile);
for (File testCaseFile : testCaseFiles) {
String fileName = testCaseFile.getAbsolutePath();
String className = fileName.replaceAll(codeSourceName + "\\\\", "")
.replaceAll(".class", "").replaceAll("\\\\", ".");
suite.addTest(new JUnit4TestAdapter(Class.forName(className)));
}
return suite;
}
protected static void listTestCase(final List<File> testCaseFiles,
final File file) {
for (File child : file.listFiles()) {
if (child.isFile()) {
if (child.getAbsolutePath().endsWith("Test.class")) {
testCaseFiles.add(child);
}
} else if (child.isDirectory()) {
AllTests.listTestCase(testCaseFiles, child);
}
}
}
}
Eclipse 3.2 では JUnit 4 はサポートされているだろうか??
May 11, 2006
[Misc] Google Trends で遊ぶ
Google Trends というサービスが新規公開された。 How does Google Trends work? によると、
Google Trends analyzes a portion of Google web searches to compute how many searches have been done for the terms you enter relative to the total number of searches done on Google over time.というサービスらしい。 試してみると、これが意外と面白い。
Google Trends の使い方
Google Trends のクエリフォーマットは How many terms can I compare? What other functionality is available? で解説されている。
You can compare up to five terms by separating each term with a comma. To compare trend info for "mittens" and "bathing suits," for example, you'd simply enter [ mittens, bathing suits ] and click on "Search Trends."要するに、
To see how many searches contained either of two terms, just separate those terms with a vertical bar: "|". For example, to determine how many searches contained the terms "mittens" or "gloves," you'd enter [ mittens | gloves ]. To compare multi-word terms, use parentheses. To see how many searches were done for either "winter mittens" or "gloves," for instance, enter [ (winter mittens) | gloves ]; otherwise, your query will be interpreted to mean all searches for "winter mittens" or "winter gloves."
You can also exclude terms from your search by using the minus sign. To see how many searches contained the term "maps" but not "google," for instance, just enter [ maps -google ].
To restrict your results to only those searches that contain your terms in the specific order you've entered them, put your terms in quotation marks. (By default, Google Trends will show you all searches that contain the terms you entered in any order.)
Note: when you use any of these advanced features -- quotation marks, minus signs, or vertical bars -- Google Trends will only display the search-volume graph. The news portion of the product doesn't support advanced functionality at this time.
- 比較したいキーワードはカンマ区切りで入力 (例、"apple,orange")
- キーワードを OR で連結する場合は '|' を使用 (例、"Revolution|Wii,PS3|(Play Station 3)")
- 特定の語彙を除外したい場合は '-' を使用 (例、"java - coffee,.Net")
Web 開発のトレンド
面白いので、Java による Web 開発関連のトレンドを調べてみた。 Application Server や IDE はなかなか面白い結果だった。
↑のボックスをクリックするとグラフが切り替わる。
May 10, 2006
[Linux] Linux で起動してからの時間を調べる方法
Linux が起動してから経過した時間を調べる方法をメモ。 起動後の経過時間は /proc/uptime から取得することができる。
一つめの値が起動後の経過時間を秒数で表した数値となる。 後は電卓を叩いて日数や時間数に換算すれば良い。 電卓を起動するのが面倒な場合は AWK で計算しても良い。# cat /proc/uptime 2700777.74 2676642.02
# cat /proc/uptime | awk '{print $1 / 60 /60 /24 "days (" $1 "sec)"}'
31.2591days (2700784.86sec)
ただしこの値、32bit でカウントされているために 500 日程度でリセットされてしまうらしい。
(ともちゃ日記さんの [Linux] uptime より)
- Manpage of PROC
- http://www.linux.or.jp/JM/html/LDP_man-pages/man5/proc.5.html
May 09, 2006
[WebService] Wikipedia API にチャレンジ
Wikipedia の API が無いものかと調べてみた。 「クローラのアクセスは止めて」と書いてあるものの普通に公開されていた。
- Wikipedia:Database download
- http://en.wikipedia.org/wiki/Wikipedia:Download#XML_schema
- XML access
- http://en.wikipedia.org/wiki/Special:Export/Title_of_the_article
- RSS access
- http://www.blinkbits.com/en_wikifeeds_rss/Title_of_the_article
XML フォーマットで記事を取得
AIBO に関する記事を XML フォーマットで取得してみた。 http://en.wikipedia.org/wiki/Special:Export/AIBO にアクセスするだけで良い。
<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/
http://www.mediawiki.org/xml/export-0.3.xsd"
version="0.3"
xml:lang="en">
<siteinfo>
<sitename>Wikipedia</sitename>
<base>http://en.wikipedia.org/wiki/Main_Page</base>
<generator>MediaWiki 1.7alpha</generator>
<case>first-letter</case>
<namespaces>
<namespace key="-2">Media</namespace>
<namespace key="-1">Special</namespace>
<namespace key="0" />
<namespace key="1">Talk</namespace>
<namespace key="2">User</namespace>
<namespace key="3">User talk</namespace>
<namespace key="4">Wikipedia</namespace>
<namespace key="5">Wikipedia talk</namespace>
<namespace key="6">Image</namespace>
<namespace key="7">Image talk</namespace>
<namespace key="8">MediaWiki</namespace>
<namespace key="9">MediaWiki talk</namespace>
<namespace key="10">Template</namespace>
<namespace key="11">Template talk</namespace>
<namespace key="12">Help</namespace>
<namespace key="13">Help talk</namespace>
<namespace key="14">Category</namespace>
<namespace key="15">Category talk</namespace>
<namespace key="100">Portal</namespace>
<namespace key="101">Portal talk</namespace>
</namespaces>
</siteinfo>
<page>
<title>AIBO</title>
<id>47087</id>
<revision>
<id>51895470</id>
<timestamp>2006-05-06T22:55:18Z</timestamp>
<contributor>
<ip>68.121.102.200</ip>
</contributor>
<comment>/* External links */</comment>
<text xml:space="preserve">[[Image:AIBO.JPG|thumb|right|The AIBO ERS-7 re
sembles a small dog]] '''AIBO''' is one of several types of [[robot|robotic]] [
[pet]]s designed and manufactured by [[Sony]]; there have been sever
中略
</text>
</revision>
</page>
</mediawiki>
RSS フォーマットで記事を取得
同じく、AIBO に関する記事を RSS フォーマットで取得してみた。 http://www.blinkbits.com/en_wikifeeds_rss/AIBO にアクセスするだけで良い。
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:annotate="http://purl.org/rss/1.0/modules/annotate/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<channel>
<title>AIBO RSS Feed for Wikipedia powered by BlinkBits.com</title>
<link>http://www.blinkbits.com/en_wikifeeds/AIBO</link>
<description>Imagine the Collective Wisdom of All Mankind Available in the
Blink of An Eye... That's BlinkBits!</description>
<managingEditor>lcotter@blinkbits.com</managingEditor>
<docs>http://www.blinkbits.com</docs>
<generator>RSS Feed 2.1.4</generator>
<language>en</language>
<lastBuildDate>Wed, 12 Apr 2006 08:09:19 -0400</lastBuildDate>
<image>
<url>http://www.blinkbits.com/images/icon_6040.gif</url>
<title>AIBO RSS Feed from Wikipedia Powered by BlinkBits.com</title>
<link>http://www.blinkbits.com</link>
<width>60</width>
<height>40</height>
</image>
<item>
<title>AIBO Wikipedia RSS Feed</title>
<link>http://www.blinkbits.com/en_wikifeeds/AIBO</link>
<pubDate>Wed, 12 Apr 2006 08:09:19 -0400</pubDate>
<guid isPermaLink="true">http://www.blinkbits.com/en_wikifeeds/AIBO</guid>
<description>
<![CDATA[ [b]AIBO[/b] is one of several types of robotic pets designed and ma
nufactured by Sony; there have been several different models since their introdu
中略
]]>
The Wikipedia article is licensed under http://www.gnu.org/copyleft/fdl.html and
uses material from http://en.wikipedia.org/wiki/AIBO. A preview of this article
is available at http://www.blinkbits.com/en_wikifeeds/AIBO.
</description>
<dc:subject>Biography</dc:subject>
<comments>http://www.blinkbits.com/en_wikifeeds/AIBO</comments>
</item>
</channel>
</rss>
May 08, 2006
[Library] JUnit 4.1 リリース
JUnit 4.1 がリリースされた。 README.html によると、4.0 からの変更点は
だそうだ。 特に大きな変更は無い模様。
- Bug fix: listeners now get a correct test running time, rather than always being told 0 secs.
- The @RunWith annotation is now inherited by subclasses: all subclasses of an abstract test class will be run by the same runner.
- The build script fails if the JUnit unit tests fail
- The faq has been updated
- Javadoc has been improved, with more internal links, and package descriptions added (Thanks, Matthias Schmidt!)
- An acknowledgements.txt file has been created to credit outside contributions
- The Enclosed runner, which runs all of the static inner classes of a given class, has been added to org.junit.runners.
ついでに JUnit4 の素敵な紹介記事を発見したのでメモ。
- developerWorks - JUnit 4の現状を紹介する
- http://www-06.ibm.com/jp/developerworks/java/051007/j_j-junit4.shtml
May 07, 2006
[Maven] Maven2 でアーカイブのファイル名を指定する
Maven2 でアーカイブを生成すると、デフォルトでは artifactId と version からファイル名が決定される。 WAR だとアーカイブファイル名がコンテキスト名として使用されるので、任意のファイル名を指定したい。 いつも設定方法を忘れるので、メモしておく。
アーカイブファイル名の指定方法
アーカイブファイル名は project/build/finalName で指定する。 ↓の例では my-war-file.war という WAR ファイルが生成される。
<?xml version="1.0"?>
<project>
<artifactId>my-artifact</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<build>
<finalName>my-war-file</finalName>
</build>
</project>



