Article View: borland.public.jbuilder.java.api
Article #447Re: RMI
From: Oliver Young
Date: Tue, 19 Aug 2003 08:52
Date: Tue, 19 Aug 2003 08:52
81 lines
5855 bytes
5855 bytes
Thank you for your help.
> If you want the classes to be loaded from the RMI codebase, you have to
> install a SecurityManager, normally an RMISecurityManager. I presumed
> you were doing this, but I should mention this because you did not show
> that in the code snippet you posted.
>
> You also need to make sure that the RMISecurityManager is installed
> *before* your program tries to load a class from the RMI codebase.
> This is more of a Java Language issue than an RMI issue.
Well, I did not have RMISecurityManager, so I added it but it did not
changed anything. Also, I've found one small RMI example and it didn't had
RMISecurityManager too, but it is working fine on my PC. So, my question is:
in which cases I need RMISecurityManager? This is how I installes securitiy
manager according to the Sun's RMI tutorial:
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
> Your main class needs to be loaded before the main method can be run
> and when that happens, all static initializers are evaluated and all
> static blocks are executed. This occurs *before* your main method is
> run.
>
> I presume your code declares and initializes a static variable of one
> of your own class types. This causes that class to be loaded before
> the main() method runs. All you need to do is to move the
> initialization. You can initialize the variable in the main() method,
> after the RMI Security Manager is installed.
The only static method or variable in my project is main() method in my app.
I've added entry to the java.policy file as stated in Sun's RMI tutorial but
it didn't changed anything:
grant {
permission java.net.SocketPermission "*:1024-65535",
"connect,accept";
permission java.net.SocketPermission "*:80", "connect";
};Here is source code of my class, I've removed everything irrelevant for
RMI and same exception still occurs:package dory2;import
java.security.*;import java.security.cert.*;import java.rmi.*;import
java.rmi.server.*;public class DoryMain { private boolean doExecute = true;
//This method below should be called as remote procedure public void
stopDory() { System.out.println("Dory stopped."); doExecute = false;
return; } public DoryMain() { if (System.getSecurityManager() == null)
{ System.setSecurityManager(new RMISecurityManager()); } String
name = "rmi://localhost:1099/StopDory"; try { StopDoryIntf rmi =
new StopDoryEngine(this); Naming.rebind(name, rmi);
System.out.println("StopDoryEngine bound"); } catch (Exception e)
{ System.err.println("StopDoryEngine exception: " +
e.getMessage()); e.printStackTrace(); } while (doExecute) {
//do something before someone calls stopDory from the outside (of my
) } } public static void main(String[] args) { DoryMain dm = new
DoryMain(); }}This is interface:package dory2;import java.rmi.*;public
interface StopDoryIntf extends Remote { public void stopDory() throws
RemoteException;}And this class:package dory2;import java.rmi.*;import
java.rmi.server.*;public class StopDoryEngine extends UnicastRemoteObject
implements StopDoryIntf{ private DoryMain dory = null; public
StopDoryEngine() throws RemoteException { super(); if
(System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager()); } } public
StopDoryEngine(DoryMain dory) throws RemoteException { if
(System.getSecurityManager() == null) { System.setSecurityManager(new
RMISecurityManager()); } this.dory = dory; } public void
stopDory() { dory.stopDory(); }}The exception
is:java.lang.NoClassDefFoundError: dory2/StopDoryIntf at
java.lang.ClassLoader.defineClass0(Native Method) at
java.lang.ClassLoader.defineClass(ClassLoader.java:502) at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123) at
java.net.URLClassLoader.defineClass(URLClassLoader.java:250) at
java.net.URLClassLoader.access$100(URLClassLoader.java:54) at
java.net.URLClassLoader$1.run(URLClassLoader.java:193) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:186) at
java.lang.ClassLoader.loadClass(ClassLoader.java:299) at
java.lang.ClassLoader.loadClass(ClassLoader.java:292) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265) at
java.lang.ClassLoader.loadClass(ClassLoader.java:255) at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)Exception in
thread "main"
Technical Details
Message-ID:
<3f41e5b2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-05!sn-xit-09!supernews.com!newsfeed.news2me.com!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!cyclone.socal.rr.com!news-west.rr.com!news.rr.com!news-out.superfeed.net!propagator2-maxim!news-in-maxim.spamkiller.net!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3f3b90c4$1@newsgroups.borland.com> <3f3e844b$1@newsgroups.borland.com> <3f40a50c@newsgroups.borland.com> <3f41a123$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,304739c9281f7628 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2003-08-19 02:09:26 PST From: "Oliver Young" <no@spam.please> Newsgroups: borland.public.jbuilder.java.api References: <3f3b90c4$1@newsgroups.borland.com> <3f3e844b$1@newsgroups.borland.com> <3f40a50c@newsgroups.borland.com> <3f41a123$1@newsgroups.borland.com> Subject: Re: RMI Date: Tue, 19 Aug 2003 10:52:51 +0200 Lines: 83 Organization: None X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 193.138.1.66 Message-ID: <3f41e5b2@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1061283250 193.138.1.66 (19 Aug 2003 01:54:10 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-05!sn-xit-09!supernews.com!newsfeed.news2me.com!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!cyclone.socal.rr.com!news-west.rr.com!news.rr.com!news-out.superfeed.net!propagator2-maxim!news-in-maxim.spamkiller.net!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail