经过两天的努力,总于在ubuntu下面编译好classpath-0.98与jamvm1.5.4,并能成功的执行类文件:jamvm hellowold,当屏幕上打印出“hello world!”的时候,按捺不住一阵兴奋!在这两天中,执行jamvm hellowold始终被有三类异常:
1) Exceptionoccurred while VM initialising
java/lang/NoClassDefFoundError: java/lang/Thread
2) Exception occured while printing exception(java/lang/NoClassDefFoundError)...
Original exception wasjava/lang/UnsatisfiedLinkError
3)segment fault
对于其中异常1), 2) 我推测可能是classpath等路径设错,我通过baidu,google,bing等搜索工具查询国内外相关问题,得出一个解决方法是:
通过jamvm –version 命令查询路径信息:
$ jamvm-version
javaversion "1.5.0"
JamVMversion 1.5.4
Copyright(C) 2003-2010 Robert Lougher <[email protected]>
Thisprogram is free software; you can redistribute it and/or
modify itunder the terms of the GNU General Public License
aspublished by the Free Software Foundation; either version 2,
or (atyour option) any later version.
Thisprogram is distributed in the hope that it will be useful,
butWITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE. Seethe
GNUGeneral Public License for more details.
Buildinformation:
ExecutionEngine: inline-threaded interpreter with stack-caching
Compiledwith: gcc 4.6.3
BootLibrary Path: /usr/local/classpath/lib/classpath
BootClass Path:
/usr/local/jamvm/share/jamvm/classes.zip:/usr/local/classpath/share/classpath/glibj.zip
在执行jamvm helloword之前需要设置两个变量:
export LD_LIBRARY_PATH=/usr/local/classpath/lib/classpath:$LD_LIBRARY_PATH
export BOOTCLASSPATH=/usr/local/jamvm/share/jamvm/classes.zip:/usr/local/classpath/share/classpath/glibj.zip
但是我按照这种方法来设置两个环境变量,还是解决不了问题;
关于异常3) 这个一定是jamvm本身的bug,除非单步条件,否则可能无法定位其问题,况且即使定位,也觉得无法解决。
在一筹莫展之时,突然搜索到一篇国际友人帖子,该贴对我的成功起了决定性的作用,真是山重水复疑无路,柳暗花明又一村!!!感谢该贴的作者!url如下:
http://www.webos-internals.org/wiki/Building_JamVM_and_GNU_Classpath_and_Jikes_(for_Java_support_in_webOS)_with_scratchbox2
具体来说,该文提到一个很关键的地方,就是在编jamvm的时候,需要enable libffi模块,否则会引起段错误!
我按照该文的步骤,一步一步走下来,最终得到了自己想要的结果!该文的应该用场景是arm,并且可以带gui,gtk等应用,而我的应用场景比较简单,即在x86下面不带gui的应该,故而我的编译和他有一些差别,具体步骤如下:
1. classpath相关操作
$ cd~/work/free
$ wgetftp://ftp.gnu.org/gnu/classpath/classpath-0.98.tar.gz
$ tarxzvf classpath-0.98.tar.gz
$ cdclasspath-0.98
$ ./configure--disable-examples --without-x --disable-qt-peer --disable-gtk-peer--disable-gconf-peer --disable-plugin --disable-alsa --disable-dssi
$ make -i
$ sudomake install -i
注: classpath的默认安装路径为/usr/local/classpath
2. jamvm相关操作
$ cd~/work/free
$ wget ftp://sourceware.org/pub/libffi/libffi-3.0.10.tar.gz
$ tarxzvf libffi-3.0.10.tar.gz
$ cdlibffi-3.0.10
$ ./configure--prefix=/usr/local
$ make
$ sudomake install
$ sudo cpinclude/ffi_common.h /usr/local/include/
$cdi686-pc-linux-gnu/
$ cdinclude/
$ sudo cpffi.h /usr/local/include
$ cd../src/86
$ sudo cpffitarget.h /usr/local/include
$ cd~/work/free
$ wget http://freefr.dl.sourceforge.net/project/jamvm/jamvm/JamVM%201.5.4/jamvm-1.5.4.tar.gz
$ tarxzvf jamvm-1.5.4.tar.gz
$ cdjamvm-1.5.4
$ CPPFLAGS="-I/usr/local/include"
$ ./configure --with-classpath-install-dir=/usr/local/classpath -enable-ffi
$ make
$ sudomake install
3. 验证jamvm
1> 已知源代码~/work/free/jamvm-1.5.4/java/helloworld.java:
public class helloworld { public static void main(String[] args) { System.out.println(“hello world!”); } } |
2> 编译 javac helloworld.java
生产helloworld.class
3> 执行jamvm helloworld 打印结果:
helloworld!
此时我们在查看CLASSPATH, LD_LIBRARY_PATH,发现:
[email protected]:~$echo $CLASSPATH
[email protected]:~$echo $LD_LIBRARY_PATH
:/usr/local/lib
cd ~/work/free/jamvm-1.5.4/java/
[email protected]:~/work/free/jamvm-1.5.4/java$jamvm test
helloworld!
可以看到,CLASSPATH与LD_LIBRARY_PATH并不需要设置成之前说的, jamvm –version显示的那些路径!!!
最后,希望该文能对遇到同样问题的兄弟们起到一定帮助!
Ubuntu12.04下jamvm1.5.4+classpath-0.98成功运行 helloworld.class