1.百度云盘或官网下载JDK压缩包jdk-8u221-linux-x64.tar.gz;该安装包是64位,具体根据安装环境选择。
2.解压安装
tar -zxf jdk-8u221-linux-x64.tar.gz
export PATH
1.下载classpath-0.98.tar.gz;http://www.gnu.org/software/classpath/downloads/downloads.html,并解压。
#tar -zxf classpath-0.98.tar.gz
#./configure --prefix=/usr/local/classpath --disable-examples --without-x --disable-qt-peer --disable-gtk-peer --disable-gconf-peer --disable-plugin --disable-alsa --disable-dssi --disable-Werror --disable-tools
#make
#make install
# tar -zxf zlib-1.2.11.tar.gz
# ./configure --prefix=/usr/local/zlib
#make
#make install
# tar -zxf libffi-3.1.tar.gz
# ./configure --prefix=/usr/local/zlib
#make
#make install
# tar -zxf jamvm-1.5.4.tar.gz
./configure --prefix=/usr/local/jamvm --with-classpath-install-dir=/usr/local/classpath --enable-ffi --disable-int-inlining CFLAGS=-I/usr/local/zlib/include LDFLAGS=-L/usr/local/zlib/lib
#make
#make install
export PATH=$PATH:/usr/local/jamvm/bin
chenchao@ubuntu:~/jamvm/jamvm-1.5.4$ 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
Compiled with: gcc 4.8.4
Boot Library Path: /usr/local/classpath/lib/classpath
Boot Class Path: /usr/local/jamvm/share/jamvm/classes.zip:/usr/local/classpath/share/classpath/glibj.zip
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
1.编码生成hello.java,编译生成hello.class,并测试。
chenchao@ubuntu:~/java$ vim hello.java
public class hello{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
chenchao@ubuntu:~/java$ javac hello.java
chenchao@ubuntu:~/java$ java hello
Hello World!
2.使用jamvm执行,如有如下输出,到此jamvm编译安装完成。
chenchao@ubuntu:~/java$ jamvm hello
Hello World!
主要关注configure配置的时候增加CC=arm-linux-gcc的交叉编译环境配置,–host=arm-linux的configure配置增加。具体根据各自的系统平台进行交叉编译,并将编译好的库文件及可执行文件放到编译时配置的对应的开发板工作目录下。同样的配置开发板上的环境变量。
OSGi架构在http://archive.eclipse.org/eclipse/equinox/下已经完成,直接下载即可。本文下载的是3.4版本,其下载的压缩包为eclipse-equinox-3.4.zip,并进行解压。
在eclipse-equinox-3.4.zip解压包中找到org.eclipse.osgi_3.4.0.v20080605-1900.jar,并运行,当出现osgi>标志证明OSGi架构已经运行。
chenchao@ubuntu:~/java$ jamvm -Dosgi.console -jar org.eclipse.osgi_3.4.0.v20080605-1900.jar
osgi>
具体可以查看OSGi架构,如何安装插件,运行、停止插件,卸载插件等。
JNI主要为java语言与C/C++之间的转换接口,在嵌入式下主要控制设备信息相关处理。如同Linux下驱动与应用一样,驱动控制物理接口。
编辑java接口文件HelloJni.java,及编译生成HelloJni.h头文件。
chenchao@ubuntu:~/jabnet$ cat HelloJni.java
public class HelloJni {
public native void sayHello();
static{
System.loadLibrary("HelloJni");
}
public static void main(String[] args) {
new HelloJni().sayHello();
}
}
chenchao@ubuntu:~/jabnet$ javac HelloJni.java
chenchao@ubuntu:~/jabnet$ javah HelloJni
根据上面的操作,已经生成了HelloJni.h头文件,该头文件生成的就是C/C++的相关对应java的接口函数名,根据该函数名编译相应的C/C++文件,HelloJni.c。编译生成libHelloJni.so。
JNIEXPORT void JNICALL Java_HelloJni_sayHello(JNIEnv *env, jobject obj){
printf("Hello net testing...\n");
}
chenchao@ubuntu:~/jabnet$ gcc -I /home/chenchao/jvm/jre64/include/ -I /home/chenchao/jvm/jre64/include/linux/ HelloJni.c -fPIC -shared -o libHelloJni.so
JAVA JDK安装目录,/home/chenchao/jvm/jre64/,根据自己的实际情况来配置。
已经根据java的接口函数sayHello(),生成了C的接口函数并实现在libHelloJni.so中。这样可以直接运行HelloJni.class测试C接口的实现。
chenchao@ubuntu:~/jnet$ java -Djava.library.path=. HelloJni
Hello net testing...
同样,通过libHelloJni.so及HelloJni.h的头文件Java_HelloJni_sayHello接口函数编译运行在需要的java上。可以通过模仿改造HelloJni.java文件。