锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲欧洲第一a在线观看,亚洲理论片在线观看,亚洲三级在线视频http://www.tkk7.com/Good-Game/category/27862.htmlzh-cnMon, 24 Dec 2007 15:26:14 GMTMon, 24 Dec 2007 15:26:14 GMT60鏀瑰彉寮鍙戞柟寮忕殑 hbm+rmichttp://www.tkk7.com/Good-Game/archive/2007/12/24/170028.htmlG_GG_GMon, 24 Dec 2007 05:36:00 GMThttp://www.tkk7.com/Good-Game/archive/2007/12/24/170028.htmlhttp://www.tkk7.com/Good-Game/comments/170028.htmlhttp://www.tkk7.com/Good-Game/archive/2007/12/24/170028.html#Feedback2http://www.tkk7.com/Good-Game/comments/commentRss/170028.htmlhttp://www.tkk7.com/Good-Game/services/trackbacks/170028.html鍦ㄦ璇昏呮渶濂藉厛鍋氬ソ涓嶄嬌鐢?IDE 鐨勫噯澶囷紙^_^!聽 鏂囨湰緙栬緫錛宒os緙栬緫鍜岃繍琛岋級
闃呰闇瑕侊細
聽java,javac,rmiregistry,rmic,ant 絳夊懡浠ゆ湁鎵娑夊強錛堝彧鏄畝鍗曚嬌鐢紝涓嶄細涔熷埆鎬曪紒錛?/font>

鍙鎬т嬌鐢ㄨ鏄庯細
聽 鎸佷箙灞傜▼搴忓憳鎴愬姛寮鍚痳miregistry鏈嶅姟錛屽湪灞鍩熺綉鍐呭叾浠栦嬌鐢ㄦ暟鎹殑闃熷弸灝卞彧瑕佸姞杞?br />hbmBean 鐨勬槧灝刯ar鍜?dao鎺ュ彛jar鍚?灝卞彲浠ュ彇寰楁暟鎹傛牴鏈劅瑙変笉鍒癶bn浣跨敤銆?br />浼樼偣錛?br />1.鍏朵粬闃熷憳緙栬瘧classpath涓笉闇瑕乭bm鐨勪換浣曚笢瑗匡紝璺熷叧娉ㄨ嚜宸變笢瑗褲?br />2.寮哄埗鎺ュ彛瑙勮寖銆?br />3.姝d氦緙栫▼銆?br />4.DAO嫻嬭瘯鎬ц兘鏂逛究銆?br />5.榪欒繕鏄?EJB 鍘熺悊錛岃漿鎹㈠鏄撱?br />
緙虹偣錛?br />1.rmic 紿佺牬鏀劇伀澧欒兘鍔涙湁闄愶紝鍙互鎹㈡垚EJB
2.澶у瀷欏圭洰娉ㄥ唽鏈嶅姟鍣紝閰嶇疆綣佺悙錛屽彲浠ヤ嬌鐢‥JB3.0


浣跨敤:
1.jdk1.5
2.jar浣跨敤錛堜負浜嗙敤hbm錛壜犅犅犅犅?
聽 聽 jta.jar;
聽聽聽 asm.jar;
聽 聽 commons-collections-2.1.1.jar;
聽 聽 commons-logging-1.0.4.jar;
聽 聽 hibernate3.jar;
聽聽聽 dom4j-1.6.1.jar;
聽聽聽 cglib-2.1.3.jar;
聽 聽 antlr-2.7.5H3.jar
聽聽聽 MYSQL.jar
3.ant1.7(浣跨敤hbm鐢熸垚 mapping;config...)
4.Middlegen-Hibernate-r5 鍚屼笂
5.浣跨敤鏂囦歡璺緞
聽 E:\rmi_test->
聽聽聽聽 +-src
聽聽聽聽 --hibernate3.xml
聽聽聽聽 --hibernate3_ant.properties

寮濮嬶細
聽1>浣跨敤ant 瀵?hbm聽 閰嶇疆鏄犲皠鍙傝?錛?/font>ant 欏圭洰瀹為檯 騫朵嬌鐢?hibernate3.xml
聽聽聽 dos 杈撳叆 -> ant -f hibernate3.xml ddl2hbm (浣跨敤浜哅iddlegen-Hibernate-r5)
聽聽聽聽聽聽聽聽聽聽聽聽 -> ant -f hibernate3.xml create_config (hibernate.cfg.xml寤虹珛)
聽聽聽 鍦?hibernate.cfg.xml涓坊鍔?> <mapping resource="hibernate\Liu.hbm.xml" />
聽聽聽 dos 杈撳叆 -> ant -f hibernate3.xml hbm2java
鍙樻垚+-src
聽聽聽聽聽聽 |-hibernate
聽聽聽聽聽聽聽聽聽 |-Liu.hbm.xml
聽聽聽聽聽聽聽聽聽 |-Liu.java
聽聽聽聽聽聽 |-hbmConfig
聽聽聽聽聽聽聽聽聽 |-hibernate.cfg.xml
聽2>鎵嬪姩寤篽bmHibernateSessionFactory鍦?/font>hbmConfig鏂囦歡涓?font color="#ffa500">(涓轟簡綆鍗昪opy->myeclipes鐢熸垚鐨?
package聽聽聽hbmConfig;聽
import聽org.hibernate.HibernateException;
import聽org.hibernate.Session;
import聽org.hibernate.cfg.Configuration;
/**
聽*聽Configures聽and聽provides聽access聽to聽Hibernate聽sessions,聽tied聽to聽the
聽*聽current聽thread聽of聽execution.聽聽Follows聽the聽Thread聽Local聽Session
聽*聽pattern,聽see聽{
@linkhttp://hibernate.org/42.html}.
*/
publicclass聽HibernateSessionFactory聽{

聽聽聽聽
/**
聽聽聽聽聽*聽Location聽of聽hibernate.cfg.xml聽file.
聽聽聽聽聽*聽NOTICE:聽Location聽should聽be聽on聽the聽classpath聽as聽Hibernate聽uses
聽聽聽聽聽*聽#resourceAsStream聽style聽lookup聽for聽its聽configuration聽file.聽That
聽聽聽聽聽*聽is聽place聽the聽config聽file聽in聽a聽Java聽package聽-聽the聽default聽location
聽聽聽聽聽*聽is聽the聽default聽Java聽package.<br><br>
聽聽聽聽聽*聽Examples:聽<br>
聽聽聽聽聽*聽<code>CONFIG_FILE_LOCATION聽=聽"/hibernate.conf.xml".聽
聽聽聽聽聽*聽CONFIG_FILE_LOCATION聽=聽"/com/foo/bar/myhiberstuff.conf.xml".</code>聽
聽聽聽聽聽
*/
聽聽聽聽
privatestatic聽String聽CONFIG_FILE_LOCATION聽="/hbmConfig/hibernate.cfg.xml";

聽聽聽聽
/**聽Holds聽a聽single聽instance聽of聽Session聽*/
聽聽聽聽
privatestaticfinal聽ThreadLocal<Session>聽threadLocal聽=new聽ThreadLocal<Session>();

聽聽聽聽
/**聽The聽single聽instance聽of聽hibernate聽configuration聽*/
聽聽聽聽
privatestaticfinal聽Configuration聽cfg聽=new聽Configuration();

聽聽聽聽
/**聽The聽single聽instance聽of聽hibernate聽SessionFactory聽*/
聽聽聽聽
privatestatic聽org.hibernate.SessionFactory聽sessionFactory;

聽聽聽聽
/**
聽聽聽聽聽*聽Returns聽the聽ThreadLocal聽Session聽instance.聽聽Lazy聽initialize
聽聽聽聽聽*聽the聽<code>SessionFactory</code>聽if聽needed.
聽聽聽聽聽*
聽聽聽聽聽*聽聽
@return聽Session
聽聽聽聽聽*聽聽
@throws聽HibernateException
聽聽聽聽聽
*/
聽聽聽聽
publicstatic聽Session聽currentSession()聽throws聽HibernateException聽{
聽聽聽聽聽聽聽聽Session聽session聽
=聽(Session)聽threadLocal.get();

聽聽聽聽聽聽聽聽
if聽(session聽==null)聽{
聽聽聽聽聽聽聽聽聽聽聽聽
if聽(sessionFactory聽==null)聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
try聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽cfg.configure(CONFIG_FILE_LOCATION);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽sessionFactory聽
=聽cfg.buildSessionFactory();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
catch聽(Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽System.err.println(
"%%%%聽Error聽Creating聽SessionFactory聽%%%%");
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽session聽
=聽sessionFactory.openSession();
聽聽聽聽聽聽聽聽聽聽聽聽threadLocal.set(session);
聽聽聽聽聽聽聽聽}

聽聽聽聽聽聽聽聽
return聽session;
聽聽聽聽}

聽聽聽聽
/**
聽聽聽聽聽*聽聽Close聽the聽single聽hibernate聽session聽instance.
聽聽聽聽聽*
聽聽聽聽聽*聽聽
@throws聽HibernateException
聽聽聽聽聽
*/
聽聽聽聽
publicstaticvoid聽closeSession()聽throws聽HibernateException聽{
聽聽聽聽聽聽聽聽Session聽session聽
=聽(Session)聽threadLocal.get();
聽聽聽聽聽聽聽聽threadLocal.set(
null);

聽聽聽聽聽聽聽聽
if聽(session聽!=null)聽{
聽聽聽聽聽聽聽聽聽聽聽聽session.close();
聽聽聽聽聽聽聽聽}
聽聽聽聽}

聽聽聽聽
/**
聽聽聽聽聽*聽Default聽constructor.
聽聽聽聽聽
*/
聽聽聽聽
private聽HibernateSessionFactory()聽{
聽聽聽聽}

}

dos涓紪璇?>
E:\rmi_test\src>javac -cp聽聽 .;D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\hibernate3.jar聽聽聽
hbmConfig/*.java


3>DAO瀹炵幇
鎺ュ彛->
package聽rmic;

import聽java.rmi.Remote;
import聽java.rmi.RemoteException;

publicinterface聽IHello聽extends聽Remote聽{
聽聽聽聽
public聽String聽sayHello(String聽id)聽throws聽RemoteException;
}

瀹炵幇綾?>
package聽rmic;

import聽java.rmi.Naming;
import聽java.rmi.RemoteException;
import聽java.rmi.server.UnicastRemoteObject;
//鍙栨秷鏄劇ず鎸囧畾鐨勭紪璇戝櫒璀﹀憡錛?br />//鍙傝兟狅細聽http://gceclub.sun.com.cn/Java_Docs/html/zh_CN/api/java/lang/SuppressWarnings.html
@SuppressWarnings("serial")
publicclass聽Hello聽extends聽UnicastRemoteObject聽implements聽IHello聽{
聽聽聽聽
public聽Hello()聽throws聽RemoteException聽{
聽聽聽聽聽聽聽聽
super();
聽聽聽聽}
聽聽聽聽
聽聽聽聽
publicvoid聽rebind(String聽name)聽{聽
聽聽聽聽聽聽聽聽
try聽{
聽聽聽聽聽聽聽聽聽聽聽聽Naming.rebind(name,
this);
聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(
"Server聽is聽running");
聽聽聽聽聽聽聽聽}聽
catch(Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽
public聽String聽sayHello(String聽id)聽throws聽RemoteException聽{
聽聽聽聽聽聽聽聽System.out.println(
"run聽Server.");
聽聽聽聽聽聽聽聽
聽聽聽聽org.hibernate.Session聽session聽
=聽hbmConfig.HibernateSessionFactory.currentSession();
聽聽聽聽org.hibernate.Query聽qu聽
=聽session.createQuery("from聽Liu聽lt聽where聽lt.id=:id");
聽聽聽聽hibernate.Liu聽ll聽
=聽(hibernate.Liu)qu.setString("id"
,id).uniqueResult();
聽聽聽聽hbmConfig.HibernateSessionFactory.closeSession();


聽聽聽聽聽聽聽聽
return"Hello聽"+ll.getName()+"聽This聽is聽processed聽by聽RMI";
聽聽聽聽}

}

dos緙栬瘧->
E:\rmi_test\src>javac -cp .;D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.
2\hibernate3.jar聽 rmic/*.java

4>java娉ㄥ唽鏈哄紑鍚?br />E:\rmi_test\src>rmiregistry 1099

5> 鏈緥綆鍗曟湇鍔″櫒寮鍚?br />
package聽start;

import聽java.rmi.RMISecurityManager;
import聽rmic.Hello聽;

publicclass聽Start聽{

聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽{
聽聽聽聽聽聽聽聽
try聽{
聽聽聽聽聽聽聽聽聽聽聽聽
//System.setSecurityManager(new聽RMISecurityManager());
聽聽聽聽聽聽聽聽聽聽聽聽new聽Hello().rebind("RMI/Mclaren");
聽聽聽聽聽聽聽聽}聽
catch(Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}

dos緙栬瘧->E:\rmi_test\src>javac聽 start/*.java
榪愯->
java -classpath .;D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\jta.jar;
D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\asm.jar;
D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\commons-collections-2.1.1.jar;
D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\commons-logging-1.0.4.jar;
D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\hibernate3.jar;
D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\dom4j-1.6.1.jar;
E:\lib\MYSQL.JAR;D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\cglib-2.1.3.jar;
E:\and\ant\bin\antlr-2.7.5H3.jar
聽 start.Start


6>瀹㈡埛绔?br />聽寰楀埌瀛樻牴Hello_Stub.class-> E:\rmi_test\src>rmic rmic.Hello
聽鎹釜鍦版柟錛歝:\\TT 騫禼opy rmic涓殑IHello.class鍜孒ello_Stub.class榪炲悓鐩綍rmic涓鍚宑opy
package聽client;

import聽java.rmi.Naming;
import聽rmic.IHello;

publicfinalclass聽Client聽{
聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽{
聽聽聽聽聽聽聽聽System.out.println(
"client.");
聽聽聽聽聽聽聽聽
try聽{
聽聽聽聽聽聽聽聽聽聽聽聽IHello聽hello聽
=聽(IHello)Naming.lookup("rmi://localhost:1099/RMI/Mclaren");
聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(hello.sayHello(
"1"));
聽聽聽聽聽聽聽聽}聽
catch(Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽聽聽}

}

聽dos緙栬瘧-> C:\TT>javac -d . Client.java
聽C:\TT>java client.Client
聽client....
聽Hello gg This is processed by RMI (gg灝辨槸鏁版嵁 鎴愬姛錛?)

mysql> select * from liu;
+----+------+-----+
| id | name | avg |
+----+------+-----+
|聽 1 | gg聽聽 |聽 24 |
+----+------+-----+










G_G 2007-12-24 13:36 鍙戣〃璇勮
]]>
璺熸垜涓璧?-鍒嗙鎸佷箙灞?rmic)http://www.tkk7.com/Good-Game/archive/2007/12/18/168547.htmlG_GG_GTue, 18 Dec 2007 09:47:00 GMThttp://www.tkk7.com/Good-Game/archive/2007/12/18/168547.htmlhttp://www.tkk7.com/Good-Game/comments/168547.htmlhttp://www.tkk7.com/Good-Game/archive/2007/12/18/168547.html#Feedback0http://www.tkk7.com/Good-Game/comments/commentRss/168547.htmlhttp://www.tkk7.com/Good-Game/services/trackbacks/168547.html鍦ㄦ錛岀壒鐣欒褰曘備嬌鐢ㄤ笉褰撴湜澶у韙婅穬鎷嶇爾錛?a id="viewpost1_TitleUrl" class="singleposttitle" href="/Good-Game/archive/2007/12/05/165530.html">EJB鍘熺悊瀛︿範_RMIC

鏁堟灉鍏堜笂 錛堜綘鐨勭粍鍛橈紝涓嶉渶瑕佹暟鎹簱錛屼笉闇瑕乭bm錛屼笉闇瑕侀厤緗枃浠訛級
瀹㈡埛绔細鍦ㄦ湇鍔″櫒寮鍚?騫禼lient绔唴classpath 鍖呭惈鏈?*_Stub.class 鍜?hbmBean絳夌被(搴曚笅鏈塧nt綆鍖栭儴緗? 鍦ㄥ唴緗戜腑闅忎究閭e彴鐢佃剳閮藉彲浠ヤ腑榪愯,閭e彴寮鍙戠數鑴?font color="#a52a2a">鍙互娌℃湁
hbm錛屽彲浠ユ病鏈夋暟鎹簱
package聽Client;

import聽java.rmi.Naming;

import聽dao.ILiuDao;
import聽dao.LiuDaoRemote;
import聽dao.imp.DaoFactory;

publicclass聽Client聽{
聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽{
聽聽聽聽聽聽聽聽
try聽{
聽聽聽聽聽聽聽聽聽聽聽聽ILiuDao聽hello聽
=聽(ILiuDao)Naming.lookup("rmi://192.168.1.109:1099/RMI/LiuDaoRemote");
聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(hello.getLiu(
"1").getName());
聽聽聽聽聽聽}聽
catch(Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}

鏈嶅姟鍣ㄧ錛?br />dao闇姹傛帴鍙B?font color="#ffa500"> 鍏朵粬闃熷憳鎻愪緵緇欑鐞嗘寔涔呭眰鐨勯槦鍛?/font>
package聽dao;

import聽java.rmi.Remote;
import聽java.rmi.RemoteException;

import聽hibernate.Customer;
import聽hibernate.Liu;

publicinterface聽ILiuDao聽extends聽Remote{
聽聽聽聽
publicabstract聽Liu聽getLiu(String聽id)聽throws聽RemoteException;
}

dao瀹炵幇
package聽dao;

import聽java.rmi.Naming;
import聽java.rmi.RemoteException;
import聽java.rmi.server.UnicastRemoteObject;

import聽org.hibernate.Query;
import聽org.hibernate.Session;

import聽hbmConfig.HibernateSessionFactory;
import聽hibernate.Customer;
import聽hibernate.Liu;

publicclass聽LiuDaoRemote聽extends聽UnicastRemoteObject聽implements聽ILiuDao聽{
聽聽聽聽
public聽LiuDaoRemote()聽throws聽RemoteException聽{
聽聽聽聽聽聽聽聽
super();
聽聽聽聽}

聽聽聽聽
public聽Liu聽getLiu(String聽id)throws聽RemoteException{
聽聽聽聽聽聽聽聽Liu聽ll聽
=聽聽null聽;
聽聽聽聽聽聽聽聽Session聽session聽
=聽HibernateSessionFactory.currentSession();
聽聽聽聽聽聽聽聽Query聽qu聽
=聽session.createQuery("from聽Liu聽lt聽where聽lt.id=:id");
聽聽聽聽聽聽聽聽ll聽
=聽(Liu)qu.setString("id",id).uniqueResult();
聽聽聽聽聽聽聽聽HibernateSessionFactory.closeSession();
聽聽聽聽聽聽聽聽
return聽ll聽;
聽聽聽聽}
}

浣跨敤ant緇欏鎴風鎻愪緵 jar

聽聽聽聽<target聽name聽=聽"rmic">
聽聽聽聽聽聽聽聽
<rmic聽base="${class}"聽includes="${rmic.package}/**/*Remote.class"/>
聽聽聽 聽聽聽 <!-- 涓や釜jar 鍖?錛岀粰瀹㈡埛绔彁渚涚殑
聽聽聽聽 聽聽聽 聽聽聽 1. rmic甯︽湁綰﹀畾鐨?鍒板叆 *_Stub.class騫墮櫎dao瀹炵幇綾伙紙*Remote.class
錛夋墦鍖?br />聽聽聽 聽聽 聽聽 聽聽 2. hbmBean 閬撳叆 hbmjava
聽 聽 聽 聽聽 -->
聽聽聽聽聽聽聽聽
<jar聽destfile="${rh.dir}/rmic.jar">
聽聽聽聽聽聽聽聽聽聽聽聽
<fileset聽dir="${class}">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽
<include聽name="${rmic.package}/**/*.class"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽
<exclude聽name="${rmic.package}/**/*Remote.class"/>
聽聽聽聽聽聽聽聽聽聽聽聽
</fileset>
聽聽聽聽聽聽聽聽
</jar>
聽聽聽聽聽聽聽聽
<jar聽destfile="${rh.dir}/hbmBean.jar">
聽聽聽聽聽聽聽聽聽聽聽聽
<fileset聽dir="${class}">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽
<include聽name="${hbm.bean.package}/**/*.class"/>
聽聽聽聽聽聽聽聽聽聽聽聽
</fileset>
聽聽聽聽聽聽聽聽
</jar>聽聽聽聽
聽聽聽聽
</target>


寮鍚湇鍔″櫒錛?br />
package聽test;

import聽java.rmi.Naming;
import聽java.rmi.RMISecurityManager;
import聽java.rmi.RemoteException;
import聽java.rmi.registry.LocateRegistry;

import聽sun.awt.AppContext;

import聽dao.DaoFactoryRemote;
import聽dao.ILiuDao;
import聽dao.LiuDaoRemote;

import聽hibernate.Liu;

publicclass聽StartMain聽{
聽聽聽聽
聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽throws聽Exception聽{
聽聽聽聽聽聽聽聽聽聽聽
try聽{聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽System.setProperty(
"java.security.policy",聽"rmi.policy");聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽LocateRegistry.createRegistry(
1099);聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽Naming.rebind(
"RMI/LiuDaoRemote",聽new聽LiuDaoRemote());聽
聽聽聽聽聽聽聽聽聽聽聽聽}聽
catch(Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽}

}






G_G 2007-12-18 17:47 鍙戣〃璇勮
]]>
EJB灝忎緥http://www.tkk7.com/Good-Game/archive/2007/12/05/165546.htmlG_GG_GWed, 05 Dec 2007 08:01:00 GMThttp://www.tkk7.com/Good-Game/archive/2007/12/05/165546.htmlhttp://www.tkk7.com/Good-Game/comments/165546.htmlhttp://www.tkk7.com/Good-Game/archive/2007/12/05/165546.html#Feedback1http://www.tkk7.com/Good-Game/comments/commentRss/165546.htmlhttp://www.tkk7.com/Good-Game/services/trackbacks/165546.html鍦ㄦ鐗瑰埆鎰熻阿錛歴ql鎶鏈兢涓?鈽嗚摑钃濆績鎯呪槄
璋㈣阿鍦ㄤ腑鍗堣繙紼嬫暀鎴?EJB
鍘熺悊鍙傝冿細EJB鍘熺悊瀛︿範_RMIC
榪欏彲鑳芥槸鎴戠涓涓狤JB 鍜屽ぇ瀹跺垎浜細
鐜錛?/strong>jboss+ejb+jdk5.0


闇瑕乯ar鍖?/b>
娉細Client涓?Test.jar 灝辨槸 EJBTest(鏈嶅姟鍣ㄦ墦鐨勫寘)



EJB緇勪歡錛?br />鎺ュ彛

package 聽org.test;

import 聽javax.ejb.Remote;

//鍦ㄦ垜鐨凟JB鍘熺悊涓粙緇?br />//鏄彲浠ヨ
rmic 鐨勬帴鍙?/font>
@Remote
public interface 聽IHello聽{
聽聽聽聽
public 聽String聽sayHello(String聽name);
}


瀹炵幇綾?/font>

package 聽org.test;

import 聽javax.ejb.Stateless;

import 聽org.jboss.annotation.ejb.RemoteBinding;

@Stateless
//璁劇疆榪滅▼JNDI鍚嶅瓧錛堣緗繙紼婮NDI鍚嶅瓧錛屽鎴風鍦ㄩ氳繃JNDI lookup鐨勬椂鍊欙紝鐢ㄧ殑灝辨槸榪欎釜鍚嶅瓧錛?
//涓嶅悓涓棿浠剁殑瀹炵幇錛岄粯璁NDI鍚嶅瓧鏄笉涓鏍風殑錛屾墍浠ヤ笉涓瀹氭槸***/Remote鎴?**/Local
//RemoteBinding鏄?jboss鐗規湁鐨?br />
@RemoteBinding(jndiBinding
= " MclarenEJB " )
public class 聽Hello聽 implements 聽IHello聽{
聽聽聽聽
public 聽String聽sayHello(String聽name)聽{
聽聽聽聽聽聽聽聽
return " Hello聽 " + name;
聽聽聽聽}
}


jdk緙栬緫+鎵撳寘鎴恓ar鍚庣儹閮ㄧ講鍒?font color="#a52a2a">%JBOSS_HOME%\server\default\deploy


瀹㈡埛绔細

import 聽java.util.Properties;

import 聽javax.naming.Context;
import 聽javax.naming.InitialContext;

import 聽org.test.IHello;


public class 聽Client聽{

聽聽聽聽
public static void 聽main(String[]聽args)聽{
聽聽聽聽聽聽聽聽
try 聽{
聽聽聽聽聽聽聽聽聽Properties聽props聽 = new 聽Properties();
聽聽聽聽聽聽聽聽聽props.put(
" java.naming.factory.initial " ,聽 " org.jnp.interfaces.NamingContextFactory " );
聽聽聽聽聽聽聽聽聽props.put(
" java.naming.provider.url " ,聽 " jnp://localhost:1099 " );
聽聽聽聽聽聽聽聽聽props.put(
" java.naming.factory.url.pkgs " ,聽 " org.jboss.naming:org.jnp.interfaces " );

聽聽聽聽聽聽聽聽聽Context聽context聽
= new 聽InitialContext(props);

聽聽聽聽聽聽聽聽聽IHello聽h聽
= 聽(IHello)聽context.lookup( " MclarenEJB " );
聽聽聽聽聽聽聽聽聽System.out.println(h.sayHello(
" EJB聽3.0聽Test " ));
聽聽聽聽聽聽聽聽}聽
catch (Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽聽聽}

}

緇撴灉鏄細
Hello EJB 3.0 Test






G_G 2007-12-05 16:01 鍙戣〃璇勮
]]>
EJB鍘熺悊瀛︿範_RMIChttp://www.tkk7.com/Good-Game/archive/2007/12/05/165530.htmlG_GG_GWed, 05 Dec 2007 07:39:00 GMThttp://www.tkk7.com/Good-Game/archive/2007/12/05/165530.htmlhttp://www.tkk7.com/Good-Game/comments/165530.htmlhttp://www.tkk7.com/Good-Game/archive/2007/12/05/165530.html#Feedback1http://www.tkk7.com/Good-Game/comments/commentRss/165530.htmlhttp://www.tkk7.com/Good-Game/services/trackbacks/165530.html鐗瑰湪嬈¢儜閲嶇殑閬撲竴澹?璋㈣阿浜?澶у摜

鍦ㄦ鎴戝氨鍒嗕韓緇欏ぇ瀹訛紝鏈漢璇█緇勭粐鑳藉姏鏈夐檺錛?/font>璇寸殑涓嶅ソ鍙埆鎬垜澶у摜鍟娿傦紙鍛靛懙錛?br />
EJB鎶鏈
浼犺緭涓婅繘琛屽皝瑁咃紝浣跨▼搴忓憳涓嶉渶瑕佸叧蹇冨お澶氱綉緇滈棶棰?/font>銆傛湇鍔″櫒閮藉熀浜庣粺涓javabean鎿嶄綔鐨?
鍦ㄨ繖灝辨槸鍩轟簬 rmic 鍛戒護錛屽拰 rmiregistry 绔彛 鏉ュ疄鐜扮殑銆?br />rmic 鍜?rmiregistry 榪欎簺閮藉湪%JAVA_HOME%/bin涓嬪彲浠ユ壘鍒般?br />涓嬮潰鎴戝氨鐢ㄥぇ鍝ョ粰鍐欑殑涓孌?娌$敤EJB瀹瑰櫒 鐨勪唬鐮佹潵鍜屽ぇ瀹跺垎浜獷JB鍘熺悊錛?br />

1.rmic鍛戒護浠嬬粛錛?br />寮曠敤錛毬?http://www.iplab.cs.tsukuba.ac.jp/liuxj/jdk1.2/zh/docs/tooldocs/solaris/rmic.html
rmic 緙栬瘧鍣ㄦ牴鎹紪璇戝悗鐨?Java 綾伙紙鍚湁榪滅▼瀵硅薄瀹炵幇錛夊悕錛屼負榪滅▼瀵硅薄鐢熸垚 stub 鍜?skeleton錛堣繙紼嬪璞℃槸鎸囧疄鐜?java.rmi.Remote 鎺ュ彛鐨勫璞★級銆?br />鍦?rmic 鍛戒護涓墍緇欑殑綾誨繀欏繪槸緇?javac 鍛戒護鎴愬姛緙栬瘧涓旀槸瀹屽叏鍖呴檺瀹氱殑綾匯備緥濡傦紝鎸夊涓嬫墍紺哄綾繪枃浠跺悕 HelloImpl 榪愯 rmic錛?br />

2.EJB緇勫緩錛?font color="#a52a2a">鏈嶅姟鍣ㄧ錛?/b>

鎺ュ彛錛?/font>
package聽org.rmi.test;

import聽java.rmi.Remote;
import聽java.rmi.RemoteException;

publicinterface聽IHello聽extends聽Remote聽{
聽聽聽聽
public聽String聽sayHello(String聽name)聽throws聽RemoteException;
}

瀹炵幇綾伙細
package聽org.rmi.test;

import聽java.rmi.Naming;
import聽java.rmi.RemoteException;
import聽java.rmi.server.UnicastRemoteObject;
//鍙栨秷鏄劇ず鎸囧畾鐨勭紪璇戝櫒璀﹀憡錛?br />//鍙傝?錛?http://gceclub.sun.com.cn/Java_Docs/html/zh_CN/api/java/lang/SuppressWarnings.html
@SuppressWarnings(
"serial")
publicclass聽Hello聽extends聽UnicastRemoteObject聽implements聽IHello聽{
聽聽聽聽
public聽Hello()聽throws聽RemoteException聽{
聽聽聽聽聽聽聽聽
super();
聽聽聽聽}
聽聽聽聽
聽聽聽聽
publicvoid聽rebind(String聽name)聽{聽
聽聽聽聽聽聽聽聽
try聽{
聽聽聽聽聽聽聽聽聽聽聽聽Naming.rebind(name,
this);
聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(
"Server聽is聽running");
聽聽聽聽聽聽聽聽}聽
catch(Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽
public聽String聽sayHello(String聽name)聽throws聽RemoteException聽{
聽聽聽聽聽聽聽聽return"Hello聽"+name+"聽This聽is聽processed聽by聽RMI";
聽聽聽聽}

}

涓婇潰鐨勭戶鎵?
java.rmi.Remote 鍜屽彲搴忓垪鍖栫殑鎰熻鏄竴鏍風殑錛涘湪緗戠粶涓漿鎴愭祦鏍煎紡鍚庯紝渚夸笌浼犺緭銆?br />
3. jdk1.5緙栬瘧鍜?
rmic 緙栬瘧鍚?/font>
聽1)javac .....
聽2)rmic聽 rmic org.rmi.test.Hello(鍚庡緱鍒?Hello_Stub.class)

4.鏈嶅姟鍣ㄥ紑鍚細
鍦ㄩ」鐩牴鐩綍涓嬪姞 rmi.policy
grant聽{
聽聽Permission聽java.security.AllPermission聽
"","connect,listen,accept";
};

鍚庤繍琛岋細
package聽org.rmi.test;

import聽java.rmi.RMISecurityManager;

publicclass聽Start聽{

聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽{
聽聽聽聽聽聽聽聽try聽{
聽聽聽聽聽聽聽聽聽聽聽聽System.setSecurityManager(
new聽RMISecurityManager());
聽聽聽聽聽聽聽聽聽聽 //榪欓噷榪樹笉澶槑鐧?/font>
聽聽聽聽聽聽聽聽聽聽聽聽
new聽Hello().rebind("RMI/Mclaren");
聽聽聽聽聽聽聽聽}聽
catch(Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽聽聽}

}

5.寮绔彛錛?/font>
rmiregistry 1099聽 錛堝紑 绔彛錛?/tt>

瀹㈡埛绔細錛堝彟鍙扮數鑴戜篃鍙互浜嗭級
import聽java.rmi.Naming;
import聽org.rmi.test.IHello;

publicfinalclass聽Client聽{
聽聽聽聽
publicstaticvoid聽main(String[]聽args)聽{
聽聽聽聽聽聽聽聽try聽{
聽聽聽聽聽聽聽聽聽聽聽聽IHello聽hello聽
=聽(IHello)Naming.lookup("rmi://localhost:1099/RMI/Mclaren");
聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(hello.sayHello(
"Mclaren"));
聽聽聽聽聽聽聽聽}聽
catch(Exception聽e)聽{
聽聽聽聽聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽聽}
聽聽聽聽}

}


緇撴灉鏄細
Hello Mclaren This is processed by RMI



G_G 2007-12-05 15:39 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 亚洲午夜一区二区电影院| 亚洲伊人成无码综合网| 亚洲精品自拍视频| 84pao国产成视频免费播放| 亚洲AV无码国产丝袜在线观看 | 亚洲美女精品视频| 97青青草原国产免费观看| 中文字幕亚洲综合久久2| 免费A级毛片无码专区| 亚洲成在人线中文字幕| 黄色成人免费网站| 亚洲 日韩 色 图网站| 在线观看亚洲免费| 一级特级aaaa毛片免费观看| 亚洲日本一区二区一本一道| a毛片在线看片免费| 亚洲第一区香蕉_国产a| 亚洲一级免费视频| 亚洲国产欧美国产综合一区| 又黄又爽的视频免费看| 中文字幕免费在线播放| 亚洲色成人网一二三区| 暖暖免费高清日本中文| a级毛片免费观看网站| 亚洲成色在线影院| 天天拍拍天天爽免费视频| 视频免费1区二区三区| 亚洲大片在线观看| 国产成人高清精品免费软件| 九九99热免费最新版| 亚洲国产综合人成综合网站00| 免费看美女被靠到爽| 国产特黄一级一片免费 | 成人毛片免费网站| 深夜福利在线视频免费| 78成人精品电影在线播放日韩精品电影一区亚洲 | 无码亚洲成a人在线观看| 日本亚洲欧洲免费天堂午夜看片女人员| 久久w5ww成w人免费| 337P日本欧洲亚洲大胆精品| 久久综合日韩亚洲精品色|