Feb 27, 2006
[Book] MIND HACKS
書籍情報
レビュー
脳の働きを紹介する書籍。 色々な実験をすることで脳の働きを実際に感じることができる。 実験は簡単なものが多いので、ネットに接続可能な PC が一台目の前にあるだけで非常に楽しめる一冊。 仕事に役に立つ類の書籍ではないが、読んで絶対損はないと思う。 本書で紹介されている簡単で面白い実験を一つ。
目の盲点
- ↓の"+"と"●"の間が 5cm くらいになるようにする
- ディスプレイから顔を 30cm くらい離す
- 左目を閉じて、右目で"+"を見る
- "+"を見たままで顔を少しずつディスプレイに近づける
- 顔を近づけて行くと、あるところで"●"が見えなくなる。
- 更に顔を近づけていくと再度"●"が見えるようになる
+ ●
ところで、この書籍で紹介されている Open EEG で脳電図の計測装置の作り方が公開されている。 少し見たところでは作るのは結構面倒そうだけれど楽しそう。 いつかチャレンジしてみたいものだ。誰か指南してくれないかな。
Feb 26, 2006
[Misc] WST の JavaScript エディタで日本語を表示する方法
WST の JavaScript エディタは、ファイルの文字エンコーディングが"US-ASCII"に指定されている。 そのため Windows-31J 等で記述された js ファイルを読み込むと 2 バイト文字は表示されない。 簡単な方法で 2 バイト文字を表示できたので、その方法をメモ。 方法は 2 通りあるので、好きな方を選択すれば良い。
ファイル単位で文字エンコーディング指定
*.js ファイルのプロパティ画面(*.js ファイルを選択して Alt+Enter) にある "Text file encoding" に文字エンコーディングを指定する。
コンボボックスには"Shift_JIS"、"Windows-31J"、"MS932"といった文字エンコーディングは存在しないが、メゲずに直接入力する。
ここでは "MS932" を指定している。
![[プロパティ画面]](/blog/entries/Misc/20060226_01/javascript_editor_01.png)
プロパティ画面で"MS932"を指定する
*.js ファイルのデフォルト文字エンコーディングを指定
"Window" → "Preferences" メニューから "General" → "ContentTypes" を選択。
"Content types" ツリーから "Text" → "JavaScript" を選択。
下の "Default encoding" が "US-ASCII" になっているので、"MS932"に書き換えて "Update" ボタンを押下。
![]() Preferences でデフォルトの文字エンコーディングを指定する |
![]() デフォルトの文字エンコーディングが "MS932" になっていることを確認する |
Feb 25, 2006
[Misc] JavaScript メモ
JavaScript 関連のドキュメントを集めてみた。 JavaScript は今まで単なる手続き型言語としてしか利用していなかったので、基本から勉強し直そうと思う。
JavaScript Guide
Netscape 社による JavaScript 関連ドキュメント。 Netscape 社のサイトには既に存在しないので、別ドメインのものを参照するしかない模様。
- Core JavaScript Guide
- http://synchro.net/docs/js/guide/index.html
- Regular Expressions
- http://synchro.net/docs/js/guide/regexp.html#1010922
- Predefined Functions
- http://synchro.net/docs/js/guide/fcns.html#1008357
- Predefined Core Objects
- http://synchro.net/docs/js/guide/obj.html#1010352
- Core JavaScript Reference
- http://synchro.net/docs/js/ref/index.html
- Chapter 1 Objects, Methods, and Properties
- http://synchro.net/docs/js/ref/objintro.html#1061890
- Chapter 2 Top-Level Properties and Functions
- http://synchro.net/docs/js/ref/toplev.html#1061890
- Appendix A Reserved Words
- http://synchro.net/docs/js/ref/keywords.html#1004016
JavaScript 入門
JavaScript によるオブジェクト指向開発の入門。 ↑のガイドやリファレンスへの取っ掛かりとして有益。 石井勝さんのドキュメントがあって、ちょっとしんみりした。
- PART 3 JavaScript言語仕様
- http://www.fureai.or.jp/~tato/JS/BOOK/BOOKSAMPL/PART3/PART3.HTM
- オブジェクト指向プログラム言語としての JavaScript
- http://www.tokumaru.org/JavaScript/
- オブジェクトなJSの基礎講座
- http://www.parkcity.ne.jp/~chaichan/src/2ndthema.htm
- Objective JavaScript
- http://web.paulownia.jp/script/
- JavaScriptによるオブジェクト指向プログラミング
- http://www.morijp.com/masarl/homepage3.nifty.com/masarl/article/js-oop.html
Eclipse による JavaScript 開発環境
Eclipse は標準では JavaScript 用のエディタを搭載していない。 普通のテキストエディタでは物悲しいので、別途プラグインをインストールする必要がある。 JavaScript Editor PlugIn for Eclipse は既に開発が終了してしまっているみたいなので、現時点(2006/02/25)では WST を選択するのがベストだろうか。
- JavaScript Editor PlugIn for Eclipse
- http://sourceforge.net/projects/jseditor
- Eclipse Web Tools Platform (WTP) Project
- http://www.eclipse.org/webtools/index.html
- wst - the web standard tools subproject
- http://www.eclipse.org/webtools/wst/main.html
Feb 23, 2006
[Derby] Derby メモ(3)
Derby のパフォーマンスに関するリファレンスをメモ。 「Derby ならでは」というものは少ない。 システムのプロパティ(derby.storage.pageCacheSize、derby.storage.pageReservedSpace、derby.storage.pageSize)くらいか。
- Performance tips and tricks
- http://db.apache.org/derby/docs/10.0/manuals/tuning/perf19.html
- derby.storage.pageCacheSize
- http://db.apache.org/derby/docs/10.1/tuning/tuning-single#N18B49
- derby.storage.pageReservedSpace
- http://db.apache.org/derby/docs/10.1/tuning/tuning-single#N18D9B
- derby.storage.pageSize
- http://db.apache.org/derby/docs/10.1/tuning/tuning-single#N18FFB
Feb 21, 2006
[Library] Struts 1.3 メモ
オレンジニュース さんの Apaxhe Struts 1.3.0 リリース で Struts 1.3 のリリースを知った。 結構たくさんアーカイブがあったので、とりあえず中身をざっと眺めてみた。
- Struts ダウンロードサイト
- http://svn.apache.org/dist/struts/
アーカイブの概要
各アーカイブの docs/index.html の内容をリスト化しておく。
- struts-action
- Struts Action Framework is a flexible control layer based on standard technologies like Java Servlets, JavaBeans, ResourceBundles, and XML, as well as various Jakarta Commons packages, like BeanUtils and Chain of Responsibility. Struts Action Framework helps you create an extensible development environment for your application, based on published standards and proven design patterns.
- struts-el
- This subproject is an extension of the Struts tag library. Each JSP custom tag in this library is a subclass of an associated tag in the Struts tag library.
- struts-extras
- The purpose of this subproject is to provide a separate and common location to provide optional but often useful extension classes to Struts Action Framework.
- struts-taglib
- This library simplifies development of a JSP-based view layer of a Struts Action Framework Application. These tags were previously packaged as part of the base Struts 1.2 distribution, but have been extracted into a separate library.
- struts-tiles
- Tiles is a templating framework. It can be used to create a common look & feel for a web site or application and to create reusable view components.
アーカイブの中身
action-library_1.3_00.zip
action-library_1.3_00
│ struts-config_1_3.dtd
│ web-app_2_3.dtd
└─action-library_1.3.0
antlr-2.7.2.jar
cactus-12-1.4.1.jar
cactus-ant-1.4.1.jar
commons-beanutils-1.7.0.jar
commons-chain-1.0.jar
commons-digester-1.6.jar
commons-fileupload-1.1.jar
commons-io-1.1.jar
commons-logging-1.0.4.jar
commons-validator-1.2.0.jar
httpunit-1.5.4.jar
junit-3.8.1.jar
oro-2.0.8.jar
struts-action-1.3.0.jar
struts-el-1.3.0.jar
struts-extras-1.3.0.jar
struts-mailreader-dao-1.3.0.jar
struts-taglib-1.3.0.jar
struts-tiles-1.3.0.jar
struts-action-1.3.0.tar.gz
struts-action-1.3.0
│ struts-action-1.3.0.jar
├─conf
│ chain-config.xml
│ struts-config_1_0.dtd
│ struts-config_1_1.dtd
│ struts-config_1_2.dtd
│ struts-config_1_3.dtd
│ validator-rules.xml
│ web-app_2_2.dtd
│ web-app_2_3.dtd
└─docs
├─apidocs
├─faqs
├─images
├─jcoverage
├─style
├─userGuide
├─xref
└─xref-test
struts-action-1.3.0-src.tar.gz
struts-action-1.3.0
│ build.xml
│ maven.xml
│ project.xml
├─build
│ maven.xml
│ pom.xml
│ project.properties
│ project.xml
│ struts.jsl
│ struts_checks.xml
│ struts_jalopy.xml
├─conf
│ └─java
│ chain-config.xml
│ struts-config_1_0.dtd
│ struts-config_1_1.dtd
│ struts-config_1_2.dtd
│ struts-config_1_3.dtd
│ validator-rules.xml
│ web-app_2_2.dtd
│ web-app_2_3.dtd
└─src
├─java
├─java
│ └─org
│ └─apache
│ └─struts
│ ├─action
│ ├─chain
│ │ ├─commands
│ │ │ ├─generic
│ │ │ ├─servlet
│ │ │ └─util
│ │ └─contexts
│ ├─config
│ │ └─impl
│ ├─mock
│ ├─upload
│ ├─util
│ └─validator
│ └─validwhen
└─test
struts-el-1.3.0
struts-el-1.3.0
│ struts-el-1.3.0.jar
└─docs
├─apidocs
├─images
├─jcoverage
├─style
├─tlddoc
├─xref
└─xref-test
struts-el-1.3.0-src.tar.gz
struts-el-1.3.0
│ build.xml
│ maven.xml
│ project.properties
│ project.xml
├─build
│ maven.xml
│ pom.xml
│ project.properties
│ project.xml
│ struts.jsl
│ struts_checks.xml
│ struts_jalopy.xml
└─src
├─exercise-taglib
├─java
│ └─org
│ └─apache
│ └─strutsel
│ └─taglib
│ ├─bean
│ ├─html
│ ├─logic
│ ├─tiles
│ └─utils
├─test
└─tld
struts-bean-el.tld
struts-html-el.tld
struts-logic-el.tld
struts-tiles-el.tld
struts-extras-1.3.0.tar.gz
struts-extras-1.3.0
│ struts-extras-1.3.0.jar
└─docs
├─apidocs
├─images
├─jcoverage
├─style
├─xref
└─xref-test
struts-extras-1.3.0-src.tar.gz
struts-extras-1.3.0
│ build.xml
│ project.properties
│ project.xml
├─build
│ maven.xml
│ pom.xml
│ project.properties
│ project.xml
│ struts.jsl
│ struts_checks.xml
│ struts_jalopy.xml
└─src
├─conf
├─java
│ └─org
│ └─apache
│ └─struts
│ ├─actions
│ ├─plugins
│ └─validator
└─test
struts-site-1.3.0.tar.gz
struts-site-1.3.0
│ struts-site-1.3.0.jar
└─docs
├─images
├─legacy
├─proposals
├─struts-doc-1.0.2
├─struts-doc-1.1
├─style
├─stylesheets
└─uml
struts-site-1.3.0-src.tar.gz
struts-site-1.3.0
│ maven.xml
│ project.properties
│ project.xml
└─build
maven.xml
pom.xml
project.properties
project.xml
struts.jsl
struts_checks.xml
struts_jalopy.xml
struts-taglib-1.3.0
struts-taglib-1.3.0
│ struts-taglib-1.3.0.jar
└─docs
├─apidocs
├─images
├─jcoverage
├─style
├─tlddoc
├─xref
└─xref-test
struts-taglib-1.3.0-src.tar.gz
struts-taglib-1.3.0
│ build.xml
│ maven.xml
│ project.properties
│ project.xml
├─build
│ maven.xml
│ pom.xml
│ project.properties
│ project.xml
│ struts.jsl
│ struts_checks.xml
│ struts_jalopy.xml
└─src
├─conf
├─java
│ └─org
│ └─apache
│ └─struts
│ └─taglib
│ ├─bean
│ ├─html
│ ├─logic
│ └─nested
│ ├─bean
│ ├─html
│ └─logic
├─test
├─test-cactus
├─tld
└─webapp
struts-tiles-1.3.0.tar.gz
struts-tiles-1.3.0
│ struts-tiles-1.3.0.jar
└─docs
├─apidocs
├─images
├─jcoverage
├─style
├─tlddoc
├─xref
└─xref-test
struts-tiles-1.3.0-src.tar.gz
struts-tiles-1.3.0
│ build.xml
│ maven.xml
│ project.properties
│ project.xml
├─build
│ maven.xml
│ pom.xml
│ project.properties
│ project.xml
│ struts.jsl
│ struts_checks.xml
│ struts_jalopy.xml
└─src
├─java
│ └─org
│ └─apache
│ └─struts
│ └─tiles
│ ├─actions
│ ├─beans
│ ├─commands
│ ├─definition
│ ├─taglib
│ │ └─util
│ └─xmlDefinition
├─resource
│ └─org
│ └─apache
│ └─struts
│ ├─resources
│ │ tiles-config_1_1.dtd
│ │ tiles-config_1_3.dtd
│ └─tiles
│ chain-config.xml
├─test
└─tld
struts-tiles.tld
Feb 20, 2006
[Mustang] SystemTray にチャレンジ
SystemTray とは
Mustang では Windows のタスクバーステータスエリアにアイコンを表示する機能が追加されたらしい。 わんこ日記さんの[Java]What's cool in AWT on Java SE 6 (Mustang)で紹介されていた。 これは面白そうなので早速チャレンジ。
- API Document - Class SystemTray
- http://java.sun.com/javase/6/docs/api/java/awt/SystemTray.html
サンプルコード
JDK 6.0beta で試してみたところ、非常に簡単に実現できた。
package jp.in_vitro.codelets.awt;
import java.awt.AWTException;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
public class Codelet {
public static void main(final String... args) throws AWTException,
InterruptedException {
Codelet me = new Codelet();
me.execute();
}
public Codelet() {
super();
}
public void execute() throws AWTException, InterruptedException {
if (SystemTray.isSupported()) {
// create PopupMenu
PopupMenu popupMenu = new PopupMenu();
MenuItem exitMenuItem = new MenuItem();
exitMenuItem.setLabel("Exit");
exitMenuItem.addActionListener(new ExitMenuItemActionListener());
popupMenu.add(exitMenuItem);
// create TrayIcon
ImageIcon image = new ImageIcon(this.getClass().getResource(
"/trayicon.jpg"));
TrayIcon icon = new TrayIcon(image.getImage());
icon.setPopupMenu(popupMenu);
// enable TrayIcon
SystemTray tray = SystemTray.getSystemTray();
tray.add(icon);
} else {
Logger.global.info("SystemTray is not supported.");
}
}
protected static class ExitMenuItemActionListener implements ActionListener {
public void actionPerformed(final ActionEvent evt) {
System.exit(0);
}
}
}
![[表示されたトレイアイコン]](/blog/entries/Mustang/20060220_01/systemtray_01.jpg)
表示されたトレイアイコン
![[ポップアップメニュー]](/blog/entries/Mustang/20060220_01/systemtray_02.jpg)
ポップアップメニュー
Feb 19, 2006
[Library] JUnit 4.0 にチャレンジ
今日は JUnit 4.0 をもう少し細かく掘り下げてみる。 ざっとソースコードを眺めてみた。
JUnitCore
JUnit 4 のテストケースを自分で実行する場合、JUnitCore を使うのが一番楽だと思う。
JUnitCore は Request や Runner を作成してテストケースを実行してくれる。
Runner
細かい作業が必要で JUnitCore が使えない場合は Runner を自分で制御する必要がある。
そういう状況は余り無いと思うけれど。
Feb 18, 2006
[Library] JUnit 4.0 にチャレンジ
長らく 3.x の時代が続いていた JUnit だけれど、遂に 4.0 がリリースされた。 というわけで、とりあえず軽く触ってみた。 4.0 がリリースされたというニュースが出ているのだが、2006/02/18 現在公式サイトには情報がなかった。 ダウンロードも 3.8.1 が最新のママ。 公式サイトで 4.0 が見つからない場合は、↓のダウンロードサイトをチェックすると良い。
- JUnit 公式サイト
- http://junit.org/index.htm
- JUnit ダウンロードサイト
- http://prdownloads.sourceforge.net/junit/
- @Test でユニットテスト - 新生 JUnit 4.0 公開
- http://pcweb.mycom.co.jp/news/2006/02/16/347.html
JUnit 4 の Annotation
JUnit 3 → 4 の大きな変更は Annotation の導入らしい。 というわけで、JUnit 4 で用意されている Annnotation をリストアップしてみた。
@After
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface After {
}
@AfterClass
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AfterClass {
}
@Before
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Before {
}
@BeforeClass
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface BeforeClass {
}
@Ignore
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Ignore {
/**
* The optional reason why the test is ignored.
*/
String value() default "";
}
@Test
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Test {
static class None extends Throwable {
private static final long serialVersionUID= 1L;
private None() {
}
}
/**
* Optionally specify <code>expected</code>, a Throwable, to cause a test method to succeed iff
* an exception of the specified class is thrown by the method.
*/
Class<? extends Throwable> expected() default None.class;
/**
* Optionally specify <code>timeout</code> in milliseconds to cause a test method to fail if it
* takes longer than that number of milliseconds.*/
long timeout() default 0L;
}
Annotation の実行タイミング
↑に挙げた Annotation は全て Target が METHOD になっている。 これら Annotation が指定されたメソッドの実行タイミングは以下の通り。
package jp.in_vitro.codelets.junit4;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.JUnitCore;
public class Codelet {
public static void main(String[] args) {
JUnitCore.runClasses(new Class[] { Codelet.class });
}
@BeforeClass
public static void beforeClass() {
Logger.global.info("beforeClass");
}
@Before
public void before() {
Logger.global.info("before");
}
@Test
public void mytest01() {
Logger.global.info("mytest01");
}
@Test
public void mytest02() {
Logger.global.info("mytest02");
}
@Test @Ignore
public void mytest03() {
Logger.global.info("mytest03");
}
@After
public void after() {
Logger.global.info("after");
}
@AfterClass
public static void afterClass() {
Logger.global.info("afterClass");
}
}
2006/02/18 17:24:32 jp.in_vitro.codelets.junit4.Codelet beforeClass 情報: beforeClass 2006/02/18 17:24:32 jp.in_vitro.codelets.junit4.Codelet before 情報: before 2006/02/18 17:24:32 jp.in_vitro.codelets.junit4.Codelet mytest01 情報: mytest01 2006/02/18 17:24:32 jp.in_vitro.codelets.junit4.Codelet after 情報: after 2006/02/18 17:24:32 jp.in_vitro.codelets.junit4.Codelet before 情報: before 2006/02/18 17:24:32 jp.in_vitro.codelets.junit4.Codelet mytest02 情報: mytest02 2006/02/18 17:24:32 jp.in_vitro.codelets.junit4.Codelet after 情報: after 2006/02/18 17:24:32 jp.in_vitro.codelets.junit4.Codelet afterClass 情報: afterClass
Assert
JUnit 4 ではテストケースが TestCase クラスを継承する必要は無くなった。 そのため、assert* メソッドは Assert クラスで定義されているものを使用する。 Assert クラスには↓のメソッドが用意されている。 これくらいの数なら static import を使っても良さそう。
static public void assertTrue(String message, boolean condition) static public void assertTrue(boolean condition) static public void assertFalse(String message, boolean condition) static public void assertFalse(boolean condition) static public void fail(String message) static public void fail() static public void assertEquals(String message, Object expected, Object actual) static public void assertEquals(Object expected, Object actual) public static void assertEquals(String message, Object[] expecteds, Object[] actuals) public static void assertEquals(Object[] expecteds, Object[] actuals) static public void assertEquals(String message, double expected, double actual, double delta) static public void assertEquals(double expected, double actual, double delta) static public void assertEquals(String message, float expected, float actual, float delta) static public void assertEquals(float expected, float actual, float delta) static public void assertNotNull(String message, Object object) static public void assertNotNull(Object object) static public void assertNull(String message, Object object) static public void assertNull(Object object) static public void assertSame(String message, Object expected, Object actual) static public void assertSame(Object expected, Object actual) static public void assertNotSame(String message, Object expected, Object actual) static public void assertNotSame(Object expected, Object actual)
Feb 16, 2006
[Mustang] Mustang Beta リリース
Mustang の Beta がついにリリースされた。 Beta リリースに伴い(?) サイトが整備されてきているみたいなので、改めてメモ。
- Java Platform, Standard Edition (Java SE) 6 Beta
- http://java.sun.com/javase/6/
- Download Java Platform, Standard Edition 6 Beta
- http://java.sun.com/javase/6/download.jsp
- JDK 6 Documentation
- http://java.sun.com/javase/6/docs/index.html
- Java Platform Standard Edition 6 API Specification
- http://java.sun.com/javase/6/docs/api/index.html
- Bug Database
- http://bugs.sun.com/bugdatabase/index.jsp
- Bug Database (Mustang 関連)
- http://bugs.sun.com/bugdatabase/search.do?process=1&category=java&bugStatus=open&subcategory=&type=bug&keyword=6.0+or+1.6
- change (Contains a list of bug fixes for each build)
- https://mustang.dev.java.net/servlets/ProjectDocumentList?folderID=2855
Feb 15, 2006
[Maven] Maven2 で JAR の Manifest ファイルを設定する方法をメモ
Maven2 の JAR アーカイバ(maven-jar-plugin) における Manifest 関連の設定をメモ。
Manifest 関連の設定方法
JAR アーカイバの Manifest 関連の設定は pom.xml に記述する。
<model>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>jp.in_vitro.dummy.Main</mainClass>
<packageName>jp.in_vitro.dummy</packageName>
<addClasspath>true</addClasspath>
<addExtensions>true</addExtensions>
<classpathPrefix>lib</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</model>
Manifest 関連の設定項目
| 設定項目 | 設定値 | 解説 |
|---|---|---|
| addClasspath | "true" / "false" | "true" が指定された場合、pom.xml の dependencies に従い Class-Path が出力される。 |
| addExtensions | "true" / "false" | "true" が指定された場合、pom.xml の dependencies に従い拡張情報(各 dependency の詳細情報)が出力される。 |
| classpathPrefix | 任意の文字列 | addClasspath に "true" が設定された際、各 Classpath エントリに指定された文字列が接頭語として付加される。例えば classpathPrefix に "lib" を指定すると、Class-Path の各エレメントは "lib/commons-logging.jar" の様になる。 |
| mainClass | 任意のクラス名(FQCN) | JAR のメインクラスを指定する。Manifest ファイルの Main-Class に出力される。 |
| packageName | 任意のパッケージ名 | JAR のパッケージを指定する。Manifest ファイルの Package に出力される。 |
Manifest 関連設定の実体
pom.xml で指定した Manifest 関連の設定は maven-archiver (maven-archiver-2.0-beta-3.jar など) にある org.apache.maven.archiver.ManifestConfiguration というクラスが保持する。 ManifestConfiguration には以下のフィールドが用意されていて、ここに設定内容がインジェクションされる。
private String mainClass; private String packageName; private String addClasspath; private String addExtensions; private String classpathPrefix;
Feb 14, 2006
[Library] Jetty にチャレンジ
Jetty とは
Jetty はオープンソースの Servlet Engine。 Tomcat と同カテゴリのソフトウェア。 Servlet Engine なので当然 Servlet をディプロイすることも可能なのだけれど、 今回は Jetty そのものをアプリケーション内に取り込んでみる。 Servlet を登録するよりもコーディングは面倒になるが、色々融通が利くようになる。
- Jetty 公式サイト
- http://jetty.mortbay.org/jetty/index.html
Jetty の初期化 & 起動
まずは Jetty を初期化する。今回使用している Jetty のバージョンは 6.0 beta8。
InputStream is = null;
Server server = null;
try {
is = this.getClass().getResourceAsStream("/jetty.xml");
XmlConfiguration configuration = new XmlConfiguration(is);
Object obj = configuration.newInstance();
server = (Server) obj;
} finally {
if (is != null) {
is.close();
}
}
MyHandler myHandler = new MyHandler();
server.setHandler(myContextHandler);
server.start();
jetty.xml はこんな↓感じ。
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC
"-//Mort Bay Consulting//DTD Configure//EN"
"http://jetty.mortbay.org/configure.dtd">
<Configure id="Server" class="org.mortbay.jetty.Server">
<Set name="ThreadPool">
<New class="org.mortbay.thread.BoundedThreadPool">
<Set name="minThreads">10</Set>
<Set name="maxThreads">100</Set>
</New>
</Set>
<Set name="connectors">
<Array type="org.mortbay.jetty.Connector">
<Item>
<New class="org.mortbay.jetty.nio.SelectChannelConnector">
<Set name="port">80</Set>
<Set name="maxIdleTime">50000</Set>
<Set name="Acceptors">10</Set>
</New>
</Item>
</Array>
</Set>
</Configure>
ハンドラの作成
リクエストを受け取ったときに実行されるハンドラを用意する。 但し、この時点では HttpSession は使えないので要注意。
public class MyHandler extends AbstractHandler {
public MyHandler() {
super();
}
public boolean handle(final String target,
final HttpServletRequest request,
final HttpServletResponse response, final int dispatch)
throws IOException, ServletException {
// TODO: ここで何か処理をする
}
}
HttpSession の準備
HttpSession を使う場合はもう少し面倒なコーディングが必要。 ハンドラを ContextHandler と SessionHandler でラッピングすると HttpSession が使用できるようになる。 ハンドラのの登録は jetty.xml を使って行っても良い。
SessionManager sessionManager = new HashSessionManager(new Random(
System.currentTimeMillis()));
sessionManager
.setMetaManager(new AbstractSessionManager.NullMetaManager());
MyHandler myHandler = new MyHandler();
SessionHandler sessionHandler = new SessionHandler();
sessionHandler.setHandler(myHandler);
sessionHandler.setSessionManager(sessionManager);
MyContextHandler myContextHandler = new MyContextHandler();
myContextHandler.setContextPath("/");
myContextHandler.setHandler(sessionHandler);
this.server.setHandler(myContextHandler);
Feb 11, 2006
[Misc] ATOK のライセンス
ATOK 2006 が届いた。
ATOK を使うのは本当に久しぶり。
以前は ATOK 派だったのだけれど、ここしばらくは PC を一人で複数台使う様になったのでライセンス代がツラくて MS-IME でガマンしていた。
しかし、最近知り合いから「ATOK のライセンスは複数台の PC へのインストールを許可している」ということを教えてもらった。
本当!? それって常識!?
というわけで、早速最新版を購入してみた。
![]()
ATOK 2006 電子辞書セット
ATOK 2006 のライセンス(部分抜粋)
確かに複数台へのインストールが許可されている。すばらしい!!
第 2 条 ご使用条件
1. 弊社は、本契約にご同意いただけたお客様が下記の各号に従い本ソフトウェアを使用することを許諾します。
(1)本ソフトウェアをお客様が占有・管理する 1 台のコンピュータに複製(インストール)しお客様ご自身(お客様が法人の場合は従業員 1 名)が使用することができます。
(2)前(1)号にかかわらず、お客様の管理のもと第 3 条に違反しない範囲で、 1 台のコンピュータにのみインストールした本ソフトウェアを複数人で使用することができます。
(3)前(1)号にかかわらず、本ソフトウェアの使用者がお客様ご自身(法人の場合は特定の従業員 1 名)に限られている場合は、本ソフトウェアを同時に使用しないという条件で、お客様(当該従業員)のみが使用する他のコンピュータにインストールすることができます。
ATOK 2006 のラインアップ
| ATOK 2006 for Windows CD-ROM |
ATOK 2006 for Windows 電子辞典セット CD-ROM |
ATOK 2006 for Windows 就活応援セット CD-ROM |
ATOK 用辞書
何か辞書を追加しようかと、どういう辞書があるのか調べてみた。 用途があるのは「広辞苑」と「角川類語新辞典」くらいか。 「日経パソコン用語辞典」は 2004 年度版しか見付からないということは売れなかったのだろうか。
Feb 09, 2006
[Derby] Derby メモ(2)
Derby を使った Java 開発に必要な情報をメモ。
- Derby Reference Manual
- http://db.apache.org/derby/docs/10.1/ref/
- Statements
- http://db.apache.org/derby/docs/10.1/ref/crefsqlj39374.html
- DataTypes
- http://db.apache.org/derby/docs/10.1/ref/crefsqlj31068.html
- Derby System Tables
- http://db.apache.org/derby/docs/10.1/ref/rrefsistabs38369.html
Derby データ型 <-> Java データ型のマッピング
Derby と Java のデータ型のマッピングを一覧表にしたものが欲しかったのだが、探した限りでは見つからなかったので自作してみた。
とは言っても、↑の DataTypes の内容を表形式にしただけのオソマツなもの。
個人的にはこれで十分だが。
| Syntax | Corresponding compile-time Java type | JDBC metadata type (java.sql.Types) | 備考 |
|---|---|---|---|
| BIGINT | java.lang.Long | BIGINT | -9223372036854775808 (java.lang.Long.MIN_VALUE) ~ 9223372036854775807 (java.lang.Long.MAX_VALUE) |
| { BLOB | BINARY LARGE OBJECT } ( length [{K |M |G }])) | java.sql.Blob | BLOB | K(1024), M(1024 * 1024), G(1024 * 1024 * 1024) |
| CHAR[ACTER] [(length)] | java.lang.String | CHAR | |
| { CHAR | CHARACTER }[(length)] FOR BIT DATA | - | BINARY | |
| {CLOB |CHARACTER LARGE OBJECT}(length [{{K |M |G}])) | java.sql.Clob | CLOB | K(1024), M(1024 * 1024), G(1024 * 1024 * 1024) |
| DATE | java.sql.Date | DATE | サポートするフォーマットは
|
| { DECIMAL | DEC } [(precision [, scale ])] | java.math.BigDecimal | DECIMAL | |
| { DOUBLE PRECISION | DOUBLE } | java.lang.Double | DOUBLE | precision は 1 ~ 31。scale は precision 以下。 |
| FLOAT [ (precision) ] | - | REAL or DOUBLE | |
| { INTEGER | INT } | java.lang.Integer | INTEGER | -2147483648 (java.lang.Integer.MIN_VALUE) ~ 2147483647 (java.lang.Integer.MAX_VALUE) |
| LONG VARCHAR | java.lang.String | LONGVARCHAR | |
| LONG VARCHAR FOR BIT DATA | - | - | |
| NUMERIC [(precision [, scale ])] | java.math.BigDecimal | NUMERIC | |
| REAL | java.lang.Float | REAL | |
| SMALLINT | java.lang.Short | SMALLINT | -32768 (java.lang.Short.MIN_VALUE) ~ 32767 (java.lang.Short.MAX_VALUE) |
| TIME | java.sql.Time | TIME | サポートするフォーマットは
|
| TIMESTAMP | java.sql.Timestamp | TIMESTAMP | サポートするフォーマットは
|
| { VARCHAR | CHAR VARYING | CHARACTER VARYING }(length) | java.lang.String | VARCHAR | The maximum length for a VARCHAR string is 32,672 characters. |
| { VARCHAR | CHAR VARYING | CHARACTER VARYING } (length) FOR BIT DATA | - | VARBINARY | The maximum size of the length value is 32,672 bytes. |
Feb 08, 2006
[VMWare] VMWare Player on Debian Sarge インストールメモ:
Debian Sarge に VMWare Player をインストールしたときのメモ。 大した障害はなかったが、Windows 版の様にインストーラ一発で終了、というわけには行かなかった。
インストール手順
- (もしインストールされていなければ) X Window System をインストール。X は VMWare Player の実行に必須の様だ。
# apt-get install x-window-system
- カーネルのバージョンに合わせてカーネルのヘッダファイルをインストールする。
# apt-get install kernel-headers-2.4.27-2-386 パッケージリストを読みこんでいます... 完了 依存関係ツリーを作成しています... 完了 以下の特別パッケージがインストールされます: kernel-headers-2.4.27-2 以下のパッケージが新たにインストールされます: kernel-headers-2.4.27-2 kernel-headers-2.4.27-2-386 アップグレード: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。 2120kB のアーカイブを取得する必要があります。 展開後に追加で 29.8MB のディスク容量が消費されます。 続行しますか? [Y/n]
- ここから Linux 版の VMWare Player をダウンロード。ここでは VMware-player-1.0.1-19317.tar.gz を使う
- VMWare Player のインストーラを実行して、インストールと初期設定を行う。
# tar zxvf ./VMware-player-1.0.1-19317.tar.gz # ./vmware-player-distrib/vmware-install.pl Creating a new installer database using the tar3 format. Installing the content of the package. In which directory do you want to install the binary files? [/usr/bin] What is the directory that contains the init directories (rc0.d/ to rc6.d/)? [/etc] What is the directory that contains the init scripts? [/etc/init.d] In which directory do you want to install the library files? [/usr/lib/vmware] The path "/usr/lib/vmware" does not exist currently. This program is going to create it, including needed parent directories. Is this what you want? [yes] yes In which directory do you want to install the documentation files? [/usr/share/doc/vmware] The path "/usr/share/doc/vmware" does not exist currently. This program is going to create it, including needed parent directories. Is this what you want? [yes] yes The installation of VMware Player 1.0.1 build-19317 for Linux completed successfully. You can decide to remove this software from your system at any time by invoking the following command: "/usr/bin/vmware-uninstall.pl". Before running VMware Player for the first time, you need to configure it by invoking the following command: "/usr/bin/vmware-config.pl". Do you want this program to invoke the command for you now? [yes] yes The correct version of one or more libraries needed to run VMware Player may be missing. This is the output of ldd /usr/bin/vmware: libm.so.6 => /lib/libm.so.6 (0x4001c000) libdl.so.2 => /lib/libdl.so.2 (0x4003e000) libpthread.so.0 => /lib/libpthread.so.0 (0x40041000) libX11.so.6 => not found libXtst.so.6 => not found libXext.so.6 => not found libXt.so.6 => not found libICE.so.6 => not found libSM.so.6 => not found libXrender.so.1 => not found libz.so.1 => /usr/lib/libz.so.1 (0x40094000) libc.so.6 => /lib/libc.so.6 (0x400a6000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) This program cannot tell for sure, but you may need to upgrade libc5 to glibc before you can run VMware Player. Hit enter to continue. Making sure services for VMware Player are stopped. Stopping VMware services: Virtual machine monitor done You must read and accept the End User License Agreement to continue. Press enter to display it. (snip) Do you accept? (yes/no) yes Thank you. Configuring fallback GTK+ 2.4 libraries. In which directory do you want to install the mime type icons? [/usr/share/icons] The path "/usr/share/icons" does not exist currently. This program is going to create it, including needed parent directories. Is this what you want? [yes] yes What directory contains your desktop menu entry files? These files have a .desktop file extension. [/usr/share/applications] In which directory do you want to install the application's icon? [/usr/share/pixmaps] Trying to find a suitable vmmon module for your running kernel. None of the pre-built vmmon modules for VMware Player is suitable for your running kernel. Do you want this program to try to build the vmmon module for your system (you need to have a C compiler installed on your system)? [yes] yes Using compiler "/usr/bin/gcc". Use environment variable CC to override. What is the location of the directory of C header files that match your running kernel? [/usr/src/linux/include] /usr/src/kernel-headers-2.4.27-2-386/include Extracting the sources of the vmmon module. Building the vmmon module. Using standalone build system. make: Entering directory `/tmp/vmware-config0/vmmon-only' make[1]: Entering directory `/tmp/vmware-config0/vmmon-only' make[2]: Entering directory `/tmp/vmware-config0/vmmon-only/driver-2.4.27-2-386' make[2]: Leaving directory `/tmp/vmware-config0/vmmon-only/driver-2.4.27-2-386' make[2]: Entering directory `/tmp/vmware-config0/vmmon-only/driver-2.4.27-2-386' make[2]: Leaving directory `/tmp/vmware-config0/vmmon-only/driver-2.4.27-2-386' make[1]: Leaving directory `/tmp/vmware-config0/vmmon-only' make: Leaving directory `/tmp/vmware-config0/vmmon-only' The module loads perfectly in the running kernel. Do you want networking for your virtual machines? (yes/no/help) [yes] yes Configuring a bridged network for vmnet0. The following bridged networks have been defined: . vmnet0 is bridged to eth0 All your ethernet interfaces are already bridged. Do you want to be able to use NAT networking in your virtual machines? (yes/no) [yes] no Do you want to be able to use host-only networking in your virtual machines? [no] no Extracting the sources of the vmnet module. Building the vmnet module. Using standalone build system. make: Entering directory `/tmp/vmware-config0/vmnet-only' make: Leaving directory `/tmp/vmware-config0/vmnet-only' The module loads perfectly in the running kernel. Would you like to enable the Google searchbar? (yes/no) [no] Starting VMware services: Virtual machine monitor done Virtual ethernet done Bridged networking on /dev/vmnet0 done The configuration of VMware Player 1.0.1 build-19317 for Linux for this running kernel completed successfully. You can now run VMware Player by invoking the following command: "/usr/bin/vmplayer". Enjoy, --the VMware team # - 後は、「X が起動した状態で」VMWare Player を起動する。
Feb 07, 2006
[VMWare] VMWare Server にチャレンジ
VMWare Server のフリー版が公開されたので、早速チャレンジ。 ダウンロードのためのユーザ登録で、"State/Province"を選択しないとダウンロードサイトが Internal Server Error になることに気付くのに時間が掛かった以外は特に問題なく進んだ。 窓の杜に書いてあるのに・・・気付けよ > 自分
- VMWare Server ダウンロードページ
- http://www.vmware.com/download/server/
- VMware Server Documentation
- http://www.vmware.com/support/pubs/server_pubs.html
- Installing the Beta
- http://www.vmware.com/support/server/doc/releasenotes_server_beta.html#install
- 窓の杜 - VMware、仮想PC作成・実行ソフトのサーバー版「VMware Server」を無償公開
- http://www.forest.impress.co.jp/article/2006/02/06/vmwareserver.html
VMWare Server インストールメモ
VMWare Server のインストールに関してメモ。
VMWare Player のセッションもそのまま引き継げて、かなり良い感じ。Feb 05, 2006
[Misc] lighttpd にチャレンジ(3)
今日は J2EE アプリケーションサーバとの連携に挑戦。 挑戦とは言ってもモジュールを 1 つ設定するだけなのだけれど。
J2EE AS 連携の設定
Apache Tomcat 5.5 と連携させてみる。
- Proxy モジュールの設定(/etc/lighttpd/conf-available/10-proxy.conf)を変更する
proxy.server = ( ".jsp" => ( ( "host" => "127.0.0.1", "port" => 8080 ) ) ) - Proxy モジュールを有効にする
# ln -s /etc/lighttpd/conf-available/10-proxy.conf /etc/lighttpd/conf-enabled/10-proxy.conf
- lighttpd を再起動
# /etc/init.d/lighttpd restart Stopping web server: lighttpd. Starting web server: lighttpd. #
- Tomcat を起動して接続を確認する。http://server/index.jsp にアクセスして Tomcat のトップ画面が表示されることを確認する。
![[lighttpd 経由で Tomcat にアクセス]](/blog/entries/Misc/20060205_01/lighttpd_access_04.png)
lighttpd 経由で Tomcat のトップ画面にアクセス(画像は Tomcat に振っていないので表示されない)
Feb 03, 2006
[Misc] lighttpd にチャレンジ(2)
昨日はとりあえず動作させるところまで試してみたので、次に Perl の CGI を試してみた。 特に悩むこともなく普通に動作できた。
Perl CGI の設定
- CGI 用の設定を有効にする
# ln -s /etc/lighttpd/conf-available/10-cgi.conf /etc/lighttpd/conf-enabled/10-cgi.conf
- lighttpd を再起動
# /etc/init.d/lighttpd restart Stopping web server: lighttpd. Starting web server: lighttpd. #
- テスト用の Perl CGI を作成する。Perl のインタプリタは lighttpd が知っているので、スクリプトの先頭に "#!/usr/bin/perl" みたいな指定をする必要はない。
# cat /var/www/index.pl print "Content-type: text/html\n\n"; print "This file is /var/www/index.pl";
![[index.plにアクセス]](/blog/entries/Misc/20060203_01/lighttpd_access_02.png)
http://dummyserver/index.pl にアクセスしてみた
PHP CGI の設定
ついでに PHP も試してみた。 lighttpd で PHP を使用する場合、"php5-cgi" や "php4-cgi" が必要となる。 Apache HTTP Server の場合は "php5" や "php4" パッケージを使っているはずなので、Apache HTTP Server で PHP を使っている環境でも別途インストール作業が必要。
- php-cgi をインストール
# apt-get install php5-cgi パッケージリストを読みこんでいます... 完了 依存関係ツリーを作成しています... 完了 提案パッケージ: php-pear 以下のパッケージが新たにインストールされます: php5-cgi アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 200 個。 4636kB のアーカイブを取得する必要があります。 展開後に追加で 10.2MB のディスク容量が消費されます。
- テスト用の PHP CGI を作成する。
# cat /var/www/index.php <html> <body> <?php print "This file is /var/www/index.php"; ?> </body> </html>
![[index.phpにアクセス]](/blog/entries/Misc/20060203_01/lighttpd_access_03.png)
http://dummyserver/index.php にアクセスしてみた
Feb 02, 2006
[Misc] lighttpd にチャレンジ
lighttpd とは
lighttpd は軽量でセキュアな Web サーバ。 比較的新しく開発されたものらしい。 @IT の記事で紹介されていて初めて知った(via hard で loxse な日々 さんの 話題のWebサーバ「lighttpd」を使うには)。 J2EE アプリケーションサーバを除くと Apache HTTP Server 以外の Web サーバはまともに触ったことがないので、興味本位で試してみることに。
- lighttpd 公式サイト
- http://www.lighttpd.net/
- 話題のWebサーバ「lighttpd」を使うには
- http://www.atmarkit.co.jp/flinux/rensai/linuxtips/842uselighttpd.html
- Linux (binary packages for FC3, SuSE, Debian, Gentoo, PLD-Linux, OpenWRT)
- BSD (FreeBSD, NetBSD, OpenBSD, MacOS X)
- SGI IRIX
- Windows (Cygwin)
- Solaris
- AIX
- and various other POSIX compatible OSes
lighttpd のインストール
まずは lighttpd をインストール。 プラットフォームは Debian Sarge。 Debian では lighttpd は unstable 扱いになっている。 ・・・というわけで、
- /etc/apt/sources.list に "deb http://http1.debian.or.jp/debian/ unstable main" を追加
- apt でパッケージを探す。
# apt-get update # apt-cache search lighttpd lighttpd - A fast webserver with minimal memory footprint lighttpd-doc - Documentation for lighttpd lighttpd-mod-mysql-vhost - MySQL-based virtual host configuration for lighttpd
- apt でインストールする。
# apt-get install lighttpd lighttpd-doc パッケージリストを読みこんでいます... 完了 依存関係ツリーを作成しています... 完了 以下の特別パッケージがインストールされます: libc6 libc6-dev libssl0.9.8 locales lsb-base 提案パッケージ: glibc-doc rrdtool 推奨パッケージ: php4-cgi php5-cgi 以下のパッケージは「削除」されます: base-config 以下のパッケージが新たにインストールされます: libssl0.9.8 lighttpd lighttpd-doc lsb-base 以下のパッケージはアップグレードされます: libc6 libc6-dev locales アップグレード: 3 個、新規インストール: 4 個、削除: 1 個、保留: 207 個。 15.1MB のアーカイブを取得する必要があります。 展開後に追加で 9249kB のディスク容量が消費されます。 続行しますか? [Y/n] Y
![[設定画面(1)]](/blog/entries/Misc/20060202_01/lighttpd_install_01.png)
設定画面(1) - Locale の登録
![[設定画面(2)]](/blog/entries/Misc/20060202_01/lighttpd_install_02.png)
設定画面(2) - 標準 Locale の選択
- インストールができたか確認する。
# /usr/sbin/lighttpd -v lighttpd-1.4.9 (ssl) - a light and fast webserver Build-Date: Jan 30 2006 12:29:26 #
- 起動確認をする。(必要であれば)Apache HTTP Server を停止して、lighttpd を起動する。lighttpd は (Debian のパッケージでは)デフォルトで 80 番ポートをバインドする。
# /etc/init.d/apache2 stop Stopping web server: Apache2. # /etc/init.d/lighttpd start Starting web server: lighttpd. #
lighttpd でページを表示してみる
lighttpd のデフォルトの設定は (Debian のパッケージでは) localhost からのアクセスしか受け付けない。 というわけで、とりあえずそれを解除してから Web ブラウザでアクセスしてみる。
- /etc/lighttpd/livhttpd.conf にある 'server.bind = "localhost"' をコメントアウトする。
- lighttpd を再起動する。
# /etc/init.d/lighttpd restart Stopping web server: lighttpd. Starting web server: lighttpd. #
- テスト用の HTML ファイルを作成する。
# cat /var/www/index.html This file is /var/www/index.html
![[lighttpdへアクセスしてみた]](/blog/entries/Misc/20060202_01/lighttpd_access_01.png)
lighttpd へアクセスしてみた
lighttpd の設定ファイル
Debian パッケージに用意されている lighttpd の設定ファイルをメモ。
- /etc/lighttpd/
- conf-available/
- 10-auth.conf
- 10-fastcgi.conf
- 10-simple-vhost.conf
- 10-userdir.conf
- 10-cgi.conf
- 10-proxy.conf
- 10-ssi.conf
- README
- conf-enabled/
- lighttpd.conf
- conf-available/

![[Preferences]](/blog/entries/Misc/20060226_01/javascript_editor_02.png)
![[プロパティ画面]](/blog/entries/Misc/20060226_01/javascript_editor_03.png)
![[VMWare Server Install失敗]](/blog/entries/VMWare/20060207_01/vmware_server_install_02.png)
![[VMWare Server Installer]](/blog/entries/VMWare/20060207_01/vmware_server_install_01.png)


