Java がこの世に出てからだいぶ経つようですが、出た当時に比べればだいぶはやっているようです。最近はJSPなどサーバで動くものも 作られています。apache.org では様々なフレームワークなどが開発されており、Javaを使うのが以前に比べて楽になりました。
ただ、Javaを使っていて少し気になる事が一つだけあります。javac JavaSource.javaと打ってからコンパイルが終わるまでの時間が かなりあるのです。コンパイラ自体もJavaで実装されているようなので、仕方がないことなのかもしれませんが、もう少し速くならないのか とよく思います。比べるのも変な話ですがせめてg++ -O0くらいにならないものでしょうか。
今回紹介したいのは、IBMのjikesという高速なJavaコンパイラです。 これはC++で実装されており、javacより5倍 ほど速いようです。半年ほど使ってみましたが、今のところバグには出会っていません。 ただ、ライブラリのパスを通さないといけなかったり、日本語など多言語環境で使う場合に文字コードを指定しなければならなかったり するので、注意点をまとめておきます。
標準的なUNIXのプログラムと同じように入れられるはずです。最近は様々なdistributionにパッケージがあるようです。 詳しいことは本家のdistributionのページを参照してください。
javacと違って、jikesはjavaの標準ライブラリの場所を知りません。そのため、ライブラリのパスを指定しないでjikesを実行すると、おそらく以下のような エラーが出ます。(MacOSX,finkの場合)
teru@server ~/src/java $ jikes lcs.java Found 1 system error: *** Semantic Error: You need to modify your classpath, sourcepath, bootclasspath, and/or extdirs setup. Package "java/lang" could not be found in: /sw/share/java/jde/bsh.jar /sw/share/java/jde/checkstyle-all.jar /sw/share/java/jde/jde.jar . . . . . . teru@server ~/src/java $
見ての通り、ライブラリのパスが見つからないのです。そこで、環境変数で教えてあげます。MacOSXならclasses.jarの位置を、
teru@server ~/src/java $ export BOOTCLASSPATH=/System/Library/Frameworks/JavaVM.framework/Classes/classes.jar
のように、また、それ以外、例えばLinuxなどはrt.jarの位置を
teru@server ~/src/java $ export BOOTCLASSPATH=/usr/java/j2sdk1.4.1/jre/lib/rt.jar
のようにすればよいでしょう。BOOTCLASSPATHは、CLASSPATHでも構いません。 前の環境変数を上書きしないように
teru@server ~/src/java $ export CLASSPATH=$CLASSPATH:/usr/java/j2sdk1.4.1/jre/lib/rt.jar
のようにするのもいいかもしれません。これらの内容は、気に入ったら.bashrcなどに追加することをおすすめします。
jikesはDefaultでは日本語などのEncodingを処理しません。そのため、ファイルに日本語などが含まれる場合は明示的にコードを 渡す必要があります。例えば、コンパイル対象のファイルがeuc-jpなら、
teru@server ~/src/java $ jikes -encoding euc-jp Somefile.java
とします。
<rindolf> rbastic: now I'm working with C++. <rindolf> rbastic: I found out that my project compiles really quickly. <rindolf> rbastic: under 5 or 10 minutes on a P4-2.4GHz with 1 GB of RAM. <rindolf> rbastic: maybe KDE is making g++ look bad. <rbastic> rindolf: yeah, i'm not a big KDE fan <rindolf> rbastic: actually I'm using KDE-3.5.8 here. <rindolf> rbastic: I was talking about the compilation speed of KDE apps and KDE itself. <rindolf> rbastic: possibly because each file has half-a-gazillion headers. <rindolf> My C++ code is a server one, so we don't have too many deps. <rbastic> yeah, isn't there a way to cache header files? ie. in their "compiled" form? <rbastic> or is that something I'm remembering from some other programming language that purported to build on top of C? <rindolf> rbastic: MSVC has that. <rbastic> ahh, nods <rindolf> rbastic: no, Visual C++ has precompiled headers. <rindolf> rbastic: I remember that I kept deleting them. <rbastic> yeah, couldn't remember <rbastic> lol <rindolf> Pascal compiles very quickly. <rindolf> That's one of the things I enjoyed in Delphi. <rbastic> ugh, the app i'm been maintaining in Java was originally a fat client/server desktop app, written in Delphi <rindolf> rbastic: ah. <rbastic> i remember booting up the old app for the first time, and being amazed at how slow it was <rbastic> eventually, i had to duplicate a feature in the Java code and i wasn't sure how it was implemented before <rindolf> rbastic: you mean the Java app is faster? :S <rbastic> so being as i had no Delphi experience, and the newer Delphi environments made NO sense to me at all, i just opened up the SQL Server query analyzer <rbastic> rindolf: yes, but only b/c the Delphi programmer was an idiot, issuing queries over and over again needlessly <rbastic> rindolf: if you could've seen the MSSQL Performance Analyzer or whatever, it was basically just.. Query1, Query2, Query3, Query1, Query2, Query3, repeat. <rbastic> it was probably the worst ive ever seen in my life.. belongs on www.thedailywtf.com -- Can I haz a fast compiler -- #perl, Freenode Good day to let down old friends who need help.