ÔÚLinuxƽ̨ÏÂʹÓÃJNI
±¾ÎļòÒª½éÉÜÁËJNIµ÷Óù淶£¬¼°³£Óú¯Êý¡£²¢Í¨¹ý¾ßÌåʾÀý³ÌÐòչʾÁËʵÏÖÒ»¸ö±¾µØµ÷ÓõĻù±¾²½Öè¡£
ÒýÑÔ
Java
µÄ³öÏÖ¸ø´ó¼Ò¿ª·¢´øÀ´µÄ¼«´óµÄ·½±ã¡£µ«ÊÇ£¬Èç¹ûÎÒÃÇÓдóÁ¿ÔÓеľ¹ý¹ã·º²âÊԵķÇJava´úÂ룬½«ËüÃÇÈ«²¿ÓÃJavaÀ´ÖØд£¬¿ÖÅ»á´øÀ´¾Þ´óµÄ¹¤×÷Á¿ºÍ³¤
ÆڵIJâÊÔ£»Èç¹ûÎÒÃǵÄÓ¦ÓÃÖÐÐèÒª·ÃÎʵ½Ìض¨µÄÉ豸£¬ÉõÖÁÊǽö·ûºÏ¹«Ë¾ÄÚ²¿ÐÅÏ¢½»»¥¹æ·¶µÄÉ豸£¬»òij¸öÌض¨µÄ²Ù×÷ϵͳ²ÅÓеÄÌØÐÔ£¬Java¾ÍÏÔµÃÓÐЩÁ¦²»´Ó
ÐÄÁË¡£Ãæ¶ÔÕâЩÎÊÌ⣬Sun¹«Ë¾ÔÚJDK1.0ÖоͶ¨ÒåÁËJNI¹æ·¶£¬Ëü¹æ¶¨ÁËJavaÓ¦ÓóÌÐò¶Ô±¾µØ·½·¨µÄµ÷ÓùæÔò¡£
ʵÏÖ²½Öè¼°Ïà¹Øº¯ÊýʹÓÃ
±¾ÎĽ«Ò»²½²½ËµÃ÷ÔÚLinuxƽ̨ÏÂÈçºÎʵÏÖ±¾µØ¹²Ïí¿âÓëJavaÐͬ¹¤×÷¡£Hello World³ÌÐòÊÇÄ¿Ç°±ê×¼µÄÈëÃŵÚÒ»²½£¬ÄÇô£¬ÎÒÒ²ÒÔÀàËƵÄÓ¦ÓÃ×îΪÑùÀý¡£
µÚÒ»²½£¬¶¨ÒåÒ»¸ö Java Àà -- Hello. ËüÌṩSayHello·½·¨£º
´ËʱӦעÒâÁ½µã£º
1.ΪҪʹÓõÄÿ¸ö±¾µØ·½·¨±àд±¾µØ·½·¨ÉùÃ÷£¬ÆäÉùÃ÷·½Ê½ÓëÆÕͨ Java ·½·¨½Ó¿Úûʲô²»Í¬£¬Ö»ÊDZØÐëÖ¸¶¨ native ¹Ø¼ü×Ö£¬ÈçÏÂËùʾ£º
public native void SayHello(String strName);
ÔÚÕâ¸öº¯ÊýÖУ¬ÎÒÃǽ«¸ù¾Ý´«½øµÄÈËÃû£¬ÏòijÈËÎʺá£
2.±ØÐëÏÔʽµØ¼ÓÔر¾µØ´úÂë¿â¡£ÎÒÃÇÐèÔÚÀàµÄÒ»¸ö¾²Ì¬¿éÖмÓÔØÕâ¸ö¿â£º
static
{
System.loadLibrary("hello");
}
ÔÙ¼ÓÉϱØÒªµÄÒì³£´¦Àí¾ÍÉú³ÉÈçÏÂÔ´ÎļþHello.java£º
public class Hello
{
static
{
try
{
//´Ë´¦¼´Îª±¾µØ·½·¨ËùÔÚÁ´½Ó¿âÃû
System.loadLibrary("hello");
}
catch(UnsatisfiedLinkError e)
{
System.err.println( "Cannot load hello library:\n " +
e.toString() );
}
}
public Hello()
{
}
//ÉùÃ÷µÄ±¾µØ·½·¨
public native void SayHello(String strName);
}
±àÒëºóÉú³ÉHello.classÎļþ¡£
µÚ¶þ²½£¬Éú³É±¾µØÁ´½Ó¿â¡£¾ßÌå¹ý³ÌÈçÏ£º
1.
ҪΪÒÔÉ϶¨ÒåµÄÀàÉú³É Java ±¾µØ½Ó¿ÚÍ·Îļþ£¬ÐèʹÓÃjavah£¬Java ±àÒëÆ÷µÄ javah ¹¦Äܽ«¸ù¾Ý
HelloÀàÉú³É±ØÒªµÄÉùÃ÷£¬´ËÃüÁÉú³ÉHello.h
Îļþ£¬ÎÒÃÇÔÚ¹²Ïí¿âµÄ´úÂëÖÐÒª°üº¬Ëü£¬javah²»Ê¹Ä¬ÈÏÄÚ²¿ÃüÁÐèÒªÖ¸Ã÷·¾¶£¬ËüÔÚJDKµÄbinĿ¼Ï£¬ÔÚÎÒµÄLinux»·¾³ÏÂÃüÁîÈçÏ£º
/home/jbuilder/jdk1.3.1/bin/javah Hello
Éú³ÉµÄHello.h Îļþ ÄÚÈÝÈçÏÂËùʾ£º
/* DO NOT EDIT THIS FILE - it
Ïà¹ØÎĵµ£º
£¨L2CAPÐÒé¼ò½é£¬L2CAPÔÚBlueZÖеÄʵÏÖÒÔ¼°L2CAP±à³Ì½Ó¿Ú£©
Ò»£ºL2CAPÐÒé¼ò½é£º
Logical Link Control and Adaptation Protocol(L2CAP)
Âß¼Á¬½Ó¿ØÖƺÍÊÊÅäÐÒé (L2CAP) ΪÉϲãÐÒéÌṩÃæÏòÁ¬½ÓºÍÎÞÁ¬½ÓµÄÊý¾Ý·þÎñ£¬²¢Ìṩ¶àÐÒ鹦ÄܺͷָîÖØ×é²Ù×÷¡£L2CAP ³äÐíÉϲãÐÒéºÍÓ¦ÓÃÈí¼þ´«ÊäºÍ½ÓÊÕ×î´ó³¤¶ÈΪ 64K µÄ L2CAP Ê ......
²Î¿¼¡¶linuxÄÚºËÍêȫעÊÍ¡·ºÍÍøÉÏÏà¹ØÎÄÕÂ
/*
* ¿ØÖÆ̨ÏÔʾ²Ù×÷
*/
/*
* linux/kernel/console.c
*
* (C) 1991 Linus Torvalds
*/
/*
* console.c
*
* This module implements the console io functions
* 'void con_init(v ......
2¡¢APACHEµÄ°²×°
1£©µ±È»»¹ÊÇÏÂÔØÔ´Âë°ü£¬È磺httpd-2.0.55.tar.gz£¬µØÖ·×Ô¼ºÕÒ……
2£©½âѹËõ£¬>tar -zxvf httpd-2.0.55.tar.gz
3£©½øÈë½âѹºóµÄhttpd-2.0.55£¬>cd httpd-2.0.55
4£©°²×°ÅäÖã¬>./configure --prefix=/opt/apache --enable-cgi
5£©±àÒ룬>make
6£©°²×°£¬>make install
......
LinuxÏÂmbstring°²×°
1¡¢ÓÃcdÃüÁî½øÈëphpµÄÔ´´úÂëĿ¼ÏµÄetc/mbstringĿ¼Ï£¬Èç“/src/php5.2.5”£¬¼´“cd /src/php5.2.5”;
2¡¢>/usr/local/php/bin/phpize £¨¼ÙÉèphp°²×°ÔÚ/usr/local/phpĿ¼Ï£©
3¡¢±àÒëÅäÖã¬>./configure --with-php-config=/usr/local/php/bin/php-config
4¡¢Ö´ÐÐ ......
¼ÙÉèphp°²×°ÔÚ/usr/local/php5/bin/php£¬³õʼÔÚÃüÁîÐÐÖ´ÐÐPHPµÄʱºòÒªÊäÈëÒ»³¤´®µÄ·¾¶£¬eg£º
$>/usr/local/php5/bin/php phpinfo.php
·Ç³£µÄÂé·³£¬ÏÖÔÚÖ»Ð轫php¿½±´ÖÁusr/sbinĿ¼¼´¿ÉÖ±½ÓʹÓÃphpÃüÁeg£º
$>cp /usr/local/php5/bin/php /usr/sbin/
$>php phpinfo.php
......