救命啊,剛開始學習rmi,問題不斷,備受打擊
按照網上的資料:
//PerfectTimeI.java
package c15.rmi;
import java.rmi.*;
interface PerfectTimeI extends Remote{
long getPerfectTime() throws RemoteException;
}
//PerfectTime
package c15.rmi;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
public class PerfectTime extends UnicastRemoteObject implements PerfectTimeI
{
public long getPerfectTime() throws RemoteException
{
return System.currentTimeMillis();
}
public PerfectTime() throws RemoteException
{
}
public static void main(String[] args) throws Exception
{
System.setSecurityManager( new RMISecurityManager());
PerfectTime pt=new PerfectTime();
Naming.bind("//localhost:2005/PerfectTime",pt);
System.out.println("Ready to do Time");
}
}
//DisplayPerfectTime
package c15.rmi;
import java.rmi.*;
import java.rmi.registry.*;
public class DisplayPerfectTime
{
public static void main(String[] args) throws Exception
{
System.setSecurityManager( new RMISecurityManager());
PerfectTimeI t=(PerfectTimeI)Naming.lookup("//localhost:2005/PerfectTime");
for(int i=0;i<10;i++)
System.out.println("Perfect time= "+t.getPerfectTime());
}
}
編譯後把PerfectTime和PerfectTimeI放在c:\java\rmi\server下面
PerfectTime和DisplayPerfectTime放在c:\java\rmi\client下面
然後用rmic產生PerfectTime_Stub.class和PerfectTime_Skel.class
然後在policy檔案裡面寫
grant {
permission java.security.AllPermission "","";
};
儲存為policy.txt放在c:\java\rmi\下面
然後 start rmiregistry 2005
然後 c:\java\RMI\server>java -Djava.rmi.server.codebase=file:///c:/java/rmi/server/ -Djava.security.policy=file:///c:/java/rmi/policy c15.rmi.PerfectTime
錯誤:
Exception in thread "main" java.security.AccessControlException: access denied (
java.net.SocketPermission 127.0.0.1:2005 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:270)
at java.security.AccessController.checkPermission(AccessController.java:
401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)
at java.net.Socket.connect(Socket.java:420)
at java.net.Socket.connect(Socket.java:376)
at java.net.Socket.<init>(Socket.java:291)
at java.net.Socket.<init>(Socket.java:119)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect
SocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
SocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185
)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
高手們幫幫忙啊,試了好幾個,都是這樣
//PerfectTimeI.java
package c15.rmi;
import java.rmi.*;
interface PerfectTimeI extends Remote{
long getPerfectTime() throws RemoteException;
}
//PerfectTime
package c15.rmi;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
public class PerfectTime extends UnicastRemoteObject implements PerfectTimeI
{
public long getPerfectTime() throws RemoteException
{
return System.currentTimeMillis();
}
public PerfectTime() throws RemoteException
{
}
public static void main(String[] args) throws Exception
{
System.setSecurityManager( new RMISecurityManager());
PerfectTime pt=new PerfectTime();
Naming.bind("//localhost:2005/PerfectTime",pt);
System.out.println("Ready to do Time");
}
}
//DisplayPerfectTime
package c15.rmi;
import java.rmi.*;
import java.rmi.registry.*;
public class DisplayPerfectTime
{
public static void main(String[] args) throws Exception
{
System.setSecurityManager( new RMISecurityManager());
PerfectTimeI t=(PerfectTimeI)Naming.lookup("//localhost:2005/PerfectTime");
for(int i=0;i<10;i++)
System.out.println("Perfect time= "+t.getPerfectTime());
}
}
編譯後把PerfectTime和PerfectTimeI放在c:\java\rmi\server下面
PerfectTime和DisplayPerfectTime放在c:\java\rmi\client下面
然後用rmic產生PerfectTime_Stub.class和PerfectTime_Skel.class
然後在policy檔案裡面寫
grant {
permission java.security.AllPermission "","";
};
儲存為policy.txt放在c:\java\rmi\下面
然後 start rmiregistry 2005
然後 c:\java\RMI\server>java -Djava.rmi.server.codebase=file:///c:/java/rmi/server/ -Djava.security.policy=file:///c:/java/rmi/policy c15.rmi.PerfectTime
錯誤:
Exception in thread "main" java.security.AccessControlException: access denied (
java.net.SocketPermission 127.0.0.1:2005 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:270)
at java.security.AccessController.checkPermission(AccessController.java:
401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)
at java.net.Socket.connect(Socket.java:420)
at java.net.Socket.connect(Socket.java:376)
at java.net.Socket.<init>(Socket.java:291)
at java.net.Socket.<init>(Socket.java:119)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect
SocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
SocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185
)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
高手們幫幫忙啊,試了好幾個,都是這樣
相關文章
- 剛開始學習nlp時遇到的問題
- iBatis問題,救命啊!!!急急急!!!BAT
- 救命啊!哪位大哥幫幫忙啊 程式出來很大的問題哦
- 解決windows記事本雙擊打不開問題薦Windows
- 現象級SUV!Model Y降價才剛剛開始,從豪華到平民,碾壓式打擊?
- 剛剛學習Jdon,安裝出現問題。求助!
- tp官網今天怎麼的打不開了啊 向攜程學習嗎
- 剛開始找工作所面臨的開發問題
- 剛開始學go要注意啥?go入門學習Go
- 不參加長沙Java培訓,想學習JAVA剛開始應該學什麼?Java
- Oracle學習遇到的問題收集及解決 - 不斷更新Oracle
- FIREFOX打不開GMAIL問題解決FirefoxAI
- 流媒體拯救了一個備受打擊的音樂產業產業
- bang救命啊! jbuilder奇怪錯誤UI
- CoreOS和Google開始反擊,Docker會受傷嗎?GoDocker
- 今天我去面試 受打擊了:你是學.net 的吧?面試
- Rmi學習筆記筆記
- 網站被攻擊導致打不開的問題分析與安全防護辦法網站
- win10開始選單打不開如何解決_win10開始選單打不開解決步驟Win10
- 剛開始接觸MAYA的你,該學習哪個模組呢?
- 嘀嗒出行IPO:挑戰剛剛開始
- windows10開始選單打不開怎麼回事_win10開始選單打不開的五個解決方案WindowsWin10
- 【DG】備庫斷檔問題
- label問題排查:打不開標註好的影像
- 我是剛開學JAVA,想請教一個問題。Java
- 從零開始學習C++之if判斷語句C++
- 救命,關於類轉換問題
- 初學,一個關於RMI的問題請教!!!
- 對於剛開始學習的人Xcode最經常使用的快捷鍵XCode
- 剛學java,關於介面的問題Java
- 開始學習啦
- 開始學習 Backbone
- 開始學習OpenRestyREST
- 初學者想問一個RMI問題
- 必須學習RMI,IIOP嗎??
- 剛開始學Web前端,用什麼軟體好?Web前端
- 執行VMWare虛擬機器報錯“打不開 /dev/vmmon:斷裂管道”的問題解決之法虛擬機dev
- 剛剛開始學習,用sudlime text執行python3時出現亂碼怎麼解決Python