[1] One Pdf document 'Java call C via JNI'
[2] Sun link of using JNI
[3] Java call C on power PC
[4] Sun book of JNI
[5] JNI and JNA in Wiki
[6] JNA intro on wiki
[7] where to download jna.jar
The JNA library uses a small native library called foreign function interface library (libffi) to dynamically invoke native code. [6]
Java Native Interface[5]
The Java Native Interface has a high overhead associated with it, making it costly to cross the boundary between code running on the JVM and native code.[69][70] Java Native Access (JNA) provides Java programs easy access to native shared libraries (DLLs on Windows) without writing anything but Java code—no JNI or native code is required. This functionality is comparable to Windows' Platform/Invoke and Python's ctypes. Access is dynamic at runtime without code generation. But it comes with a cost and JNA is usually slower than JNI.[71]
Monday, August 22, 2011
Tuesday, August 9, 2011
Monday, August 8, 2011
Sunday, August 7, 2011
C Call Java function under Linux/Windows
[1] Ref from codeproject
[q.yang@localhost CTest]$ ll
total 16
-rwxr--r-- 1 q.yang developer 7298 2011-08-05 15:03 CTest.cpp
drwxr-xr-x 2 q.yang developer 4096 2011-08-08 11:31 debug
-rwxr--r-- 1 q.yang developer 838 2011-08-08 11:32 makefile
[q.yang@localhost CTest]$ echo $JAVA_HOME
/usr/java/default
[q.yang@localhost CTest]$ pwd
/home/q.yang/EclipseCDT/qywkspace/Sandbox/Sample_017_CCallJava_via_JNI/CTest
[q.yang@localhost CTest]$ cat makefile
DESTDIR = ./debug
PROGRAM = $(DESTDIR)/CCallJava
SRCDIR = ./
CC = g++
OBJS := $(addprefix $(DESTDIR)/,CTest.o)
DEBUG = -g
CFLAGS = -Wall -c $(DEBUG) -D GSN_HOST_NOT_SUPPORT_RD_CONFIG
INCL = -I ./include -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux
LIB_FLAGS = -ljvm
LD_FLAGS = -L $(JAVA_HOME)/jre/lib/i386/server/ -L $(JAVA_HOME)/jre/lib/i386/
#-----------------------------------------------
#Compile and Link Image
#------------------------------------------------
all: $(PROGRAM)
$(PROGRAM): $(OBJS)
$(CC) -o $(PROGRAM) $(OBJS) -pthread $(LD_FLAGS) $(LIB_FLAGS)
$(DESTDIR)/%.o:$(SRCDIR)/%.cpp
$(CC) -c $(CFLAGS) $< -o $@ $(INCL)
#-----------------------------------------------
#Clean obj and image files.
#------------------------------------------------
clean :
rm -f $(OBJS)
rm -f $(PROGRAM)
COMPILE ALL JAVA PROGRAM
------------------------------
[q.yang@localhost TestStruct]$ javac *.java
RUN C PROGRAM TO CALL JAVA FUNCTION
------------------------------------
[q.yang@localhost Sandbox]$ tree Sample_017_CCallJava_via_JNI/
Sample_017_CCallJava_via_JNI/
|-- CTest
| |-- CTest.cpp
| |-- debug
| | |-- CCallJava
| | `-- CTest.o
| `-- makefile
|-- JavaSrc
| `-- TestStruct
| |-- ControlDetail.class
| |-- ControlDetail.java
| |-- HelloWorld.class
| |-- HelloWorld.java
| |-- ReturnData.class
| |-- ReturnData.java
| |-- WorkOrder.class
| `-- WorkOrder.java
`-- readme.txt
[q.yang@localhost CTest]$ export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/i386/server/:$JAVA_HOME/jre/lib/i386/
[q.yang@localhost CTest]$ echo $LD_LIBRARY_PATH
/usr/java/default/jre/lib/i386/server/:/usr/java/default/jre/lib/i386/
[q.yang@localhost debug]$ ./CCallJava
Struct Created in C has values:
ID:11
Name:HR-HW
IP:10.32.164.133
Port:9099
Hello World!
This is the main function in HelloWorld class
TestCall:Called from the C Program
Going to Call DisplayStruct
Structure is:
-------------------------
Name:HR-HW
IP:10.32.164.133
Port9099
Going to call DisplayStructArray From C
WorkOrders are Given hereunder:
----------------------------
<---Work Order Number:1<---
Sum_Serial_ID: 2000
Access_Number: 2878430
Action_Type: 04
Effective_Date: 25-12-2007 12:20:30 PM
Fetch_Flag: 0
Reason: Executed Successfully
Access_Source: PMS
<---Work Order Number:2<---
Sum_Serial_ID: 1000
Access_Number: 2878000
Action_Type: T4
Effective_Date: 25-12-2007 11:20:30 PM
Fetch_Flag: 0
Reason:
Access_Source: RMS
Going to return an object from java
Values Returned from Object are:
returnValue=1
Log=Successfull function call
[q.yang@localhost debug]$
[q.yang@localhost CTest]$ ll
total 16
-rwxr--r-- 1 q.yang developer 7298 2011-08-05 15:03 CTest.cpp
drwxr-xr-x 2 q.yang developer 4096 2011-08-08 11:31 debug
-rwxr--r-- 1 q.yang developer 838 2011-08-08 11:32 makefile
[q.yang@localhost CTest]$ echo $JAVA_HOME
/usr/java/default
[q.yang@localhost CTest]$ pwd
/home/q.yang/EclipseCDT/qywkspace/Sandbox/Sample_017_CCallJava_via_JNI/CTest
[q.yang@localhost CTest]$ cat makefile
DESTDIR = ./debug
PROGRAM = $(DESTDIR)/CCallJava
SRCDIR = ./
CC = g++
OBJS := $(addprefix $(DESTDIR)/,CTest.o)
DEBUG = -g
CFLAGS = -Wall -c $(DEBUG) -D GSN_HOST_NOT_SUPPORT_RD_CONFIG
INCL = -I ./include -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux
LIB_FLAGS = -ljvm
LD_FLAGS = -L $(JAVA_HOME)/jre/lib/i386/server/ -L $(JAVA_HOME)/jre/lib/i386/
#-----------------------------------------------
#Compile and Link Image
#------------------------------------------------
all: $(PROGRAM)
$(PROGRAM): $(OBJS)
$(CC) -o $(PROGRAM) $(OBJS) -pthread $(LD_FLAGS) $(LIB_FLAGS)
$(DESTDIR)/%.o:$(SRCDIR)/%.cpp
$(CC) -c $(CFLAGS) $< -o $@ $(INCL)
#-----------------------------------------------
#Clean obj and image files.
#------------------------------------------------
clean :
rm -f $(OBJS)
rm -f $(PROGRAM)
COMPILE ALL JAVA PROGRAM
------------------------------
[q.yang@localhost TestStruct]$ javac *.java
RUN C PROGRAM TO CALL JAVA FUNCTION
------------------------------------
[q.yang@localhost Sandbox]$ tree Sample_017_CCallJava_via_JNI/
Sample_017_CCallJava_via_JNI/
|-- CTest
| |-- CTest.cpp
| |-- debug
| | |-- CCallJava
| | `-- CTest.o
| `-- makefile
|-- JavaSrc
| `-- TestStruct
| |-- ControlDetail.class
| |-- ControlDetail.java
| |-- HelloWorld.class
| |-- HelloWorld.java
| |-- ReturnData.class
| |-- ReturnData.java
| |-- WorkOrder.class
| `-- WorkOrder.java
`-- readme.txt
[q.yang@localhost CTest]$ export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/i386/server/:$JAVA_HOME/jre/lib/i386/
[q.yang@localhost CTest]$ echo $LD_LIBRARY_PATH
/usr/java/default/jre/lib/i386/server/:/usr/java/default/jre/lib/i386/
[q.yang@localhost debug]$ ./CCallJava
Struct Created in C has values:
ID:11
Name:HR-HW
IP:10.32.164.133
Port:9099
Hello World!
This is the main function in HelloWorld class
TestCall:Called from the C Program
Going to Call DisplayStruct
Structure is:
-------------------------
Name:HR-HW
IP:10.32.164.133
Port9099
Going to call DisplayStructArray From C
WorkOrders are Given hereunder:
----------------------------
<---Work Order Number:1<---
Sum_Serial_ID: 2000
Access_Number: 2878430
Action_Type: 04
Effective_Date: 25-12-2007 12:20:30 PM
Fetch_Flag: 0
Reason: Executed Successfully
Access_Source: PMS
<---Work Order Number:2<---
Sum_Serial_ID: 1000
Access_Number: 2878000
Action_Type: T4
Effective_Date: 25-12-2007 11:20:30 PM
Fetch_Flag: 0
Reason:
Access_Source: RMS
Going to return an object from java
Values Returned from Object are:
returnValue=1
Log=Successfull function call
[q.yang@localhost debug]$
Install VLC Player for ubuntu 10.10
[1] Web source Link
Command line way
You need to check that a universe mirror is listed in your /etc/apt/sources.list file.
% sudo apt-get update
% sudo apt-get install vlc vlc-plugin-pulse mozilla-plugin-vlc
Command line way
You need to check that a universe mirror is listed in your /etc/apt/sources.list file.
% sudo apt-get update
% sudo apt-get install vlc vlc-plugin-pulse mozilla-plugin-vlc
Friday, August 5, 2011
Install Java SE JDK6 under Fedora 9
[1] http://www.oracle.com/technetwork/java/javase/install-linux-rpm-137089.html
[2] http://fedoraunity.org/Members/zcat/using-sun-java-instead-of-openjdk
[q.yang@localhost Download]$ ./jdk-6u26-linux-i586-rpm.bin
[q.yang@localhost Download]$ ./jdk-6u26-linux-i586-rpm.bin
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
inflating: jdk-6u26-linux-i586.rpm
inflating: sun-javadb-common-10.6.2-1.1.i386.rpm
inflating: sun-javadb-core-10.6.2-1.1.i386.rpm
inflating: sun-javadb-client-10.6.2-1.1.i386.rpm
inflating: sun-javadb-demo-10.6.2-1.1.i386.rpm
inflating: sun-javadb-docs-10.6.2-1.1.i386.rpm
inflating: sun-javadb-javadoc-10.6.2-1.1.i386.rpm
error: can't create transaction lock on /var/lib/rpm/__db.000
Installing JavaDB
error: can't create transaction lock on /var/lib/rpm/__db.000
Done.
[q.yang@localhost Download]$ su
Password:
[root@localhost Download]# ./jdk-6u26-linux-i586-rpm.bin
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
replace jdk-6u26-linux-i586.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: jdk-6u26-linux-i586.rpm
replace sun-javadb-common-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-common-10.6.2-1.1.i386.rpm
replace sun-javadb-core-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-core-10.6.2-1.1.i386.rpm
replace sun-javadb-client-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-client-10.6.2-1.1.i386.rpm
replace sun-javadb-demo-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-demo-10.6.2-1.1.i386.rpm
replace sun-javadb-docs-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-docs-10.6.2-1.1.i386.rpm
replace sun-javadb-javadoc-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
inflating: sun-javadb-javadoc-10.6.2-1.1.i386.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
plugin.jar...
javaws.jar...
deploy.jar...
Installing JavaDB
Preparing... ########################################### [100%]
1:sun-javadb-common ########################################### [ 17%]
2:sun-javadb-core ########################################### [ 33%]
3:sun-javadb-client ########################################### [ 50%]
4:sun-javadb-demo ########################################### [ 67%]
5:sun-javadb-docs ########################################### [ 83%]
6:sun-javadb-javadoc ########################################### [100%]
Java(TM) SE Development Kit 6 successfully installed.
Product Registration is FREE and includes many benefits:
* Notification of new versions, patches, and updates
* Special offers on Oracle products, services and training
* Access to early releases and documentation
Product and system data will be collected. If your configuration
supports a browser, the JDK Product Registration form will
be presented. If you do not register, none of this information
will be saved. You may also register your JDK later by
opening the register.html file (located in the JDK installation
directory) in a browser.
For more information on what data Registration collects and
how it is managed and used, see:
http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html
Press Enter to continue.....
Done.
[root@localhost Download]# exit
exit
[q.yang@localhost Download]$ java -version
java version "1.6.0"
OpenJDK Runtime Environment (build 1.6.0-b09)
OpenJDK Client VM (build 1.6.0-b09, mixed mode)
[q.yang@localhost Download]$
CHANGE DEFAULT JDK TO SUN INSTEAD OF OPEN JDK [2]
----------------------------------------------
[q.yang@localhost ~]$ source /etc/profile.d/sunjava.sh
[q.yang@localhost ~]$ echo $PATH
/usr/java/default/bin:/usr/java/default/bin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/bin:/usr/bin:/home/q.yang/bin:/sbin:/usr/sbin:/opt/wx/2.8/bin:/opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin:/opt/codeblocks20100721-svn/bin/:/home/q.yang/CodeSourcery/arm-2010q1/bin:/opt/codeblocks20100721-svn/bin:/home/q.yang/EclipseCDT/eclipse
[q.yang@localhost ~]$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
[q.yang@localhost ~]$ cat /etc/profile.d/sunjava.sh
export JAVA_HOME=/usr/java/default
export PATH=$JAVA_HOME/bin:$PATH
[2] http://fedoraunity.org/Members/zcat/using-sun-java-instead-of-openjdk
[q.yang@localhost Download]$ ./jdk-6u26-linux-i586-rpm.bin
[q.yang@localhost Download]$ ./jdk-6u26-linux-i586-rpm.bin
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
inflating: jdk-6u26-linux-i586.rpm
inflating: sun-javadb-common-10.6.2-1.1.i386.rpm
inflating: sun-javadb-core-10.6.2-1.1.i386.rpm
inflating: sun-javadb-client-10.6.2-1.1.i386.rpm
inflating: sun-javadb-demo-10.6.2-1.1.i386.rpm
inflating: sun-javadb-docs-10.6.2-1.1.i386.rpm
inflating: sun-javadb-javadoc-10.6.2-1.1.i386.rpm
error: can't create transaction lock on /var/lib/rpm/__db.000
Installing JavaDB
error: can't create transaction lock on /var/lib/rpm/__db.000
Done.
[q.yang@localhost Download]$ su
Password:
[root@localhost Download]# ./jdk-6u26-linux-i586-rpm.bin
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
replace jdk-6u26-linux-i586.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: jdk-6u26-linux-i586.rpm
replace sun-javadb-common-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-common-10.6.2-1.1.i386.rpm
replace sun-javadb-core-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-core-10.6.2-1.1.i386.rpm
replace sun-javadb-client-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-client-10.6.2-1.1.i386.rpm
replace sun-javadb-demo-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-demo-10.6.2-1.1.i386.rpm
replace sun-javadb-docs-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-docs-10.6.2-1.1.i386.rpm
replace sun-javadb-javadoc-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
inflating: sun-javadb-javadoc-10.6.2-1.1.i386.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
plugin.jar...
javaws.jar...
deploy.jar...
Installing JavaDB
Preparing... ########################################### [100%]
1:sun-javadb-common ########################################### [ 17%]
2:sun-javadb-core ########################################### [ 33%]
3:sun-javadb-client ########################################### [ 50%]
4:sun-javadb-demo ########################################### [ 67%]
5:sun-javadb-docs ########################################### [ 83%]
6:sun-javadb-javadoc ########################################### [100%]
Java(TM) SE Development Kit 6 successfully installed.
Product Registration is FREE and includes many benefits:
* Notification of new versions, patches, and updates
* Special offers on Oracle products, services and training
* Access to early releases and documentation
Product and system data will be collected. If your configuration
supports a browser, the JDK Product Registration form will
be presented. If you do not register, none of this information
will be saved. You may also register your JDK later by
opening the register.html file (located in the JDK installation
directory) in a browser.
For more information on what data Registration collects and
how it is managed and used, see:
http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html
Press Enter to continue.....
Done.
[root@localhost Download]# exit
exit
[q.yang@localhost Download]$ java -version
java version "1.6.0"
OpenJDK Runtime Environment (build 1.6.0-b09)
OpenJDK Client VM (build 1.6.0-b09, mixed mode)
[q.yang@localhost Download]$
CHANGE DEFAULT JDK TO SUN INSTEAD OF OPEN JDK [2]
----------------------------------------------
[q.yang@localhost ~]$ source /etc/profile.d/sunjava.sh
[q.yang@localhost ~]$ echo $PATH
/usr/java/default/bin:/usr/java/default/bin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/bin:/usr/bin:/home/q.yang/bin:/sbin:/usr/sbin:/opt/wx/2.8/bin:/opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin:/opt/codeblocks20100721-svn/bin/:/home/q.yang/CodeSourcery/arm-2010q1/bin:/opt/codeblocks20100721-svn/bin:/home/q.yang/EclipseCDT/eclipse
[q.yang@localhost ~]$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
[q.yang@localhost ~]$ cat /etc/profile.d/sunjava.sh
export JAVA_HOME=/usr/java/default
export PATH=$JAVA_HOME/bin:$PATH
Wednesday, August 3, 2011
Change MAC address under Linux
[1] http://www.linuxquestions.org/questions/linux-software-2/how-to-change-mac-address-304234/
[root@localhost ltib]# ifconfig eth0 down hw ether 00:0C:F1:87:56:F8
[root@localhost ltib]# ifconfig eth0 down hw ether 00:0C:F1:87:56:F8
Subscribe to:
Posts (Atom)