javaµ÷ÓÃdllÀý×Ó
×î¼Ñ´ð°¸
1. ±àд·¶ÀýÎĵµ
public class TestNative
{
private native static int Max(int a,int b);
public static void main(String[] args)
{
System.out.println(Max(4,5));
}
static
{
System.loadLibrary("VCdll");
}
}
ÆäÖÐ
LoadLibraryÖеÄDLLÎļþÃû³Æ¿ÉÒÔËæ±ã¶¨.Ö»Òª×öºÃµÄ¶¯Ì¬Á´½Ó¿â¸ÄÃû³ÉÕâ¸ö×Ö·û´®¾Í¿ÉÒÔÁË.¶ønativeº¯ÊýµÄÀ´Ô´¾ÍÊǸö¯Ì¬Á´½Ó¿â.
2. ×öºÃ¸Ã²½×¼±¸ÒÔºó,ÓÃjavac TestNative.javaÉú³ÉTestNative.class. ¼ìÑéÓï·¨.
3. Óï·¨¼ì²éͨ¹ýÒÔºó,ÓÃjavah TestNativeÉú³ÉTestNative.hµÄC++Í·Îļþ.
4. ÓÃVC++6.0´´½¨dllÎļþ:
<1>msdev->new->project->win32 Dynamic-Link Library
<2>Enter project name (e.g. VCdll)
<3>choose "An empty DLL project"->finish
<4>½«3Éú³ÉµÄTestNative.hºÍjdkϵÄjni.hºÍjni_md.h¼ÓÈëµ½¹¤³ÌÖÐÈ¥
<5>Create a c++ file, implements the native method. as follows:
//TestNative.cpp
#include "TestNative.h"
JNIEXPORT jint JNICALL Java_TestNative_Max
(JNIEnv * a, jclass b, jint x, jint y)
{
return x > y ? x : y;
}
±¸×¢:
A ÆäÖеÄjni.hͨ³£ÔÚ jdk\include\ ¿ÉÒÔÏÈ¿½±´µ½VC°²×°Ä¿Â¼ÏµÄincludeĿ¼ÏÂ.Ò»ÀÍÓÀÒÝ,ÒÔºó¿ÉÒÔ·½±ãʹÓÃJNI¼¼Êõ.
B È«²¿µÄÊý¾ÝÀàÐÍÐèÒª¿¼ÂÇJavaºÍVCµÄ½Ó¿ÚÎÊÌâ.ÓÃjint jstring µÈ.
C º¯ÊýÃû³ÆºÍ×Ô¶¯Éú³ÉµÄ.hÎļþÖй涨µÄÒ»ÖÂ.ÃüÃû¹æÔòÊÇ: Java_ʹÓÃÀà_·½·¨Ãû
6. È«±àÒëÒ»ÏÂVC++¹¤³Ì.
Èç¹ûûÓгö´í,Ôò´ËʱÉú³É¶¯Ì¬Á´½Ó¿â³É¹¦.
°Ñ¶¯Ì¬Á´½Ó¿âVCdll.dll¿½±´µ½TestNative.javaËùÔÚµÄĿ¼ÉÏ.
7.ÔËÐÐjava TestNative. OK :-)
Ïà¹ØÎĵµ£º
ÔںܶàJavaÓ¦ÓÃÖÐÐèÒªÔÚ³ÌÐòÖе÷ÓÃJava±àÒëÆ÷À´±àÒëºÍÔËÐС£µ«ÔÚÔçÆڵİ汾ÖУ¨Java SE5¼°ÒÔÇ°°æ±¾£©ÖÐÖ»ÄÜͨ¹ýtools.jarÖеÄcom.sun.tools.javac°üÀ´µ÷ÓÃJava±àÒëÆ÷£¬µ«ÓÉÓÚtools.jar²»ÊDZê×¼µÄJava¿â£¬ÔÚʹÓÃʱ±ØÐëÒªÉèÖÃÕâ¸öjarµÄ·¾¶¡£¶øÔÚJava SE6ÖÐΪÎÒÃÇÌṩÁ˱ê×¼µÄ°üÀ´²Ù×÷Java±àÒëÆ÷£¬Õâ¾ÍÊÇjavax.tools°ü¡£Ê¹ÓÃÕ ......
Java¿ª·¢ÖУ¬×îÖյijÌÐò·¢²¼Ò»°ãÊÇÒª´ò³Éjar°üÐÎʽµÄ£¬¶øÓÐһЩÅäÖÃÎļþÊÇ·ÅÔÚjarÀïÃæµÄ£¬ÕâÑùÔÚ×öFileÐÎʽµÄ¶Áȡʱ£¬¾Í»á·¢ÏÖ¶Á²»µ½ÏàÓ¦µÄÎļþ¡£ÏÂÃæÌṩһÖÖ½â¾ö·½Ê½£ºString fileName = "/config/abcd.config";
InputStream in = getClass().getResourceAsStream(fileName);
BufferedReader br = null;
try{
br = n ......
<!--
/* Font Definitions */
@font-face
{font-family:SimSun;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:ËÎÌå;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@SimSun&qu ......
´úÂëÈçÏ£º
¡¡¡¡ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º
¡¡¡¡package com.example.pinyin.demo2;
¡¡¡¡import net.sourceforge.pinyin4j.PinyinHelper;
¡¡¡¡import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
¡¡¡¡import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
¡¡¡¡import net.sourceforge.pinyin4j.form ......
java´ò°ü-exeÎļþ-×îÖÕÒÔsetupÐÎʽ·¢²¼µÄ½â¾öÖ®µÀ
java´ò°ü-exeÎļþ-×îÖÕÒÔsetupÐÎʽ·¢²¼µÄ½â¾öÖ®µÀ
Ê×ÏÈ£¬½«±àÒëºÃµÄ³ÌÐò´ò°ü³ÉjarÎļþ£¬È»ºó×ö³öexe£¬ÕâÑù´úÂë¾Í²»¿É¼ûÁË£»µ«ÊÇexeÎļþÔÚûÓа²×°jreµÄµçÄÔÉϲ»ÄÜÔËÐУ¬Èç¹ûÒªÇó¿Í»§ÔÙÈ¥°²×°jre ÉèÖû·¾³±äÁ¿ ¾Í²»ÑÅÁË¡£ÎÒÃÇÐèÒª½«jre´ò°ü¡£
Õ⼸²½²Ù×÷Í ......