java version
"
1.5.0
"
JamVM version
1.5
.
4
Copyright (C)
2003
-
2010
Robert Lougher
<
rob@jamvm.org.uk
>
This program
is
free software; you can redistribute it
and
/
or
modify it under the terms of the GNU General
Public
License
as
published by the Free Software Foundation; either version
2
,
or
(at your
option
) any later version.
This program
is
distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY
or
FITNESS
FOR
A PARTICULAR PURPOSE. See the
GNU General
Public
License
for
more details.
Build information:
Execution Engine: direct
-
threaded interpreter
with
stack
-
caching
Compiled
with
: gcc
4.6
.
2
20110630
(prerelease)
Boot Library Path:
/
usr
/
classpath
/
lib
/
classpath
Boot Class Path:
/
usr
/
jamvm
/
share
/
jamvm
/
classes.zip:
/
usr
/
classpath
/
share
/
classpath
/
glibj.zip
交叉编译环境前提已经搭建好
各个软件版本及下载地址:
GNU Classpath 0.98 http://www.gnu.org/software/classpath/downloads/downloads.html
JVM 1.54 https://sourceforge.net/projects/jamvm/files/jamvm/
zlib 1.2.11 http://www.zlib.net/
libffi 3.2 ftp://sourceware.org/pub/libffi/
编译过程:
一、编译gnu classpath
前提:
1、在/usr下创建classpath文件夹,并赋予权限 :sudo chmod 777 /usr/classpath -R
2、将文件解压并将文件夹赋予权限 sudo chmod 777 ~/software/classpath-0.98 -R
编译安装:
1、./configure --prefix=/usr/javatools --host=arm-none-linux-gnueabi
--disable-examples --without-x --disable-qt-peer --disable-gtk-peer
--disable-gconf-peer --disable-plugin --disable-alsa --disable-dssi
--disable-Werror --disable-tools
说明:直接执行,会报错conditional "GCJ_JAVAC" was never defined.
根据百度的结果,解决方式是假设GCJ
没有定义,但是它也没有用到过,则就在.configure文件中把那个if判断用#屏蔽了 2、make & make install
二、编译zlib
前提:
1、在/usr下创建zlib文件夹,并赋予权限:sudo chmod 777 /usr/zlib -R
2、将文件解压并将文件夹赋予权限:sudo chmod 777 ~/software/zlib-1.2.11 -R
编译安装:
1、
export CC=arm-linux-gcc
./configure --prefix=/usr/zlib
2、make & make install
三、编译libffi
前提:
1、将libffi同样安装在/usr/zlib文件夹下
2、将文件解压并将文件夹赋予权限:sudo chmod 777 ~/software/libffi-3.2 -R
编译安装:
1、./configure --prefix=/usr/zlib --host=arm-none-linux-gnueabi
2、make & make install
拷贝文件:
将/usr/zlib/lib/libffi-3.2/include/
将里面的ffi.h ffitarget.h
复制到/usr/zlib/include中。
四、编译jvm 前提:
1、在/usr下创建jamvm文件夹,并赋予权限:sudo chmod 777 /usr/jamvm -R
2、将文件解压并将文件夹赋予权限:sudo chmod 777 ~/software/jamvm-1.54 -R
编译安装:
1、./configure --prefix=/usr/jamvm --with-classpath-install-dir=/usr/classpath --enable-ffi --disable-int-inlining --host=arm-none-linux-gnueabi CFLAGS=-I/usr/zlib/include LDFLAGS=-L/usr/zlib/lib
2、make & make install
安装到开发板并配置环境变量
1、
将classpath和jamvm两个文件夹复制到开发板的
/usr目录下面
2、将zlib/lib中的所有文件夹和文件拷贝到开发板的/usr/lib/目录下面
3、配置环境变量
export PATH=$PATH:/usr/jamvm/bin
jamvm -version
打印版本信息如下:
java version "1.5.0"
JamVM version 1.5.4
Copyright (C) 2003-2010 Robert Lougher <rob@jamvm.org.uk>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2,
or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Build information:
Execution Engine: direct-threaded interpreter with stack-caching
Compiled with: gcc 4.6.2 20110630 (prerelease)
Boot Library Path: /usr/classpath/lib/classpath
Boot Class Path: /usr/jamvm/share/jamvm/classes.zip:/usr/classpath/share/classpath/glibj.zip
将红色部分设置到环境变量中:
export LD_LIBRARY_PATH=/usr/classpath/lib/classpath:$LD_LIBRARY_PATH
export BOOTCLASSPATH=/usr/jamvm/share/jamvm/classes.zip:/usr/classpath/share/classpath/glibj.zip
该命令可以每次都执行一次,也可以写到开发板的启动文件中,这样就不用每次都手动执行。启动文件不同开发板不一样,自己去添加环境变量,此处不再叙述。
java程序:
public class HelloWorld {
public static void main(String[] args){
System.out.println("Hello World!");
}
}
编译 javac HelloWorld
将生成的HelloWorld.class拷贝到开发板上执行jamvm HelloWorld
打印Hello World!
遇到的问题:
1、执行config和make主要是三类问题,没有执行权限,利用chmod 777 将文件夹所有权限赋值;缺少依赖库,主要是zlib和ffi,下载安装即可;config配置错误,按照当前的没有问题;
2、库拷贝问题,zlib/lib库未拷贝,会产生找不到lib库的问题;
3、执行的时候还报如下错误,可能三种原因导致:环境变量设置错误;classpath和jamvm版本不正确;java程序的位置不对。
Exceptionoccurred while VM initialising
Java/lang/NoClassDefFoundError: java/lang/Thread
4、之前试了classpath0.99和jamvm2.0.0,一直报第三个错误,直到变成当前的版本,坑啊!
5、java程序的位置不要定义包就好了。