Thread View: borland.public.jbuilder.java.api
13 messages
13 total messages
Started by Oliver Young
Thu, 14 Aug 2003 13:39
RMI
Author: Oliver Young
Date: Thu, 14 Aug 2003 13:39
Date: Thu, 14 Aug 2003 13:39
27 lines
2076 bytes
2076 bytes
I got following error:
java.lang.NoClassDefFoundError: dory2/StopDory
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"
when compiling with:
String name = "rmi://localhost:1099/dory2.StopDoryEngine";
StopDoryEngine rmi = new StopDoryEngine();
Naming.rebind(name, rmi);
exception occurs after compilation and before app enters "main" method.
What is this?
Re: RMI
Author: John McGrath [TeamB]
Date: Sat, 16 Aug 2003 19:21
Date: Sat, 16 Aug 2003 19:21
40 lines
2654 bytes
2654 bytes
On 8/14/2003 at 9:39:18 AM, Oliver Young wrote: > java.lang.NoClassDefFoundError: dory2/StopDory > 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" > > when compiling with: > > String name = "rmi://localhost:1099/dory2.StopDoryEngine"; > StopDoryEngine rmi = new StopDoryEngine(); > Naming.rebind(name, rmi); > > exception occurs after compilation and before app enters "main" > method. What is this? What seems to be happening is that the application ClassLoader is trying to load the dory2.StopDory class. It does not find it on the class path so it is trying to load it from the RMI codebase. The reason this is happening before your main program runs is probably because you have a class (static) variable initialization that requires the class to be loaded. -- Regards, John McGrath [TeamB]
Re: RMI
Author: Oliver Young
Date: Mon, 18 Aug 2003 05:13
Date: Mon, 18 Aug 2003 05:13
4 lines
1216 bytes
1216 bytes
> What seems to be happening is that the application ClassLoader is > trying to load the dory2.StopDory class. dory2.StopDory is an interface not a class.
Re: RMI
Author: Tor Iver Wilhelmsen (TeamB)
Date: Mon, 18 Aug 2003 06:58
Date: Mon, 18 Aug 2003 06:58
6 lines
1252 bytes
1252 bytes
"Oliver Young" <no@spam.please> writes: > dory2.StopDory is an interface not a class. The main difference between an interface and a class is a flag: They both come from class files and need to be resolved by the ClassLoader.
Re: RMI
Author: Oliver Young
Date: Mon, 18 Aug 2003 10:04
Date: Mon, 18 Aug 2003 10:04
10 lines
1498 bytes
1498 bytes
> What seems to be happening is that the application ClassLoader is > trying to load the dory2.StopDory class. It does not find it on the > class path so it is trying to load it from the RMI codebase. Well, it should load it from RMI, that is why I'm using RMI. > The reason this is happening before your main program runs is probably > because you have a class (static) variable initialization that requires > the class to be loaded. Could you, please, tell me what to do? I'm not fluent with RMI.
Re: RMI
Author: John McGrath [TeamB]
Date: Tue, 19 Aug 2003 03:35
Date: Tue, 19 Aug 2003 03:35
20 lines
1758 bytes
1758 bytes
On 8/18/2003 at 1:13:28 AM, Oliver Young wrote: > > What seems to be happening is that the application ClassLoader is > > trying to load the dory2.StopDory class. > dory2.StopDory is an interface not a class. In this context, it does not make any difference. Just substitute "interface" for "class" in my message and it is still accurate. In Java, the term "class" is often used to include interfaces. Take the class "ClassLoader" for example. A ClassLoader loads both classes and interfaces. Perhaps it would be more accurate to call it something like "ClassAndInterfaceLoader" or "NonPrimitiveTypeLoader", but they chose the shorter name instead. -- Regards, John McGrath [TeamB]
Re: RMI
Author: John McGrath [TeamB]
Date: Tue, 19 Aug 2003 04:01
Date: Tue, 19 Aug 2003 04:01
36 lines
2687 bytes
2687 bytes
On 8/18/2003 at 6:04:35 AM, Oliver Young wrote: > > What seems to be happening is that the application ClassLoader is > > trying to load the dory2.StopDory class. It does not find it on the > > class path so it is trying to load it from the RMI codebase. > Well, it should load it from RMI, that is why I'm using RMI. > > > The reason this is happening before your main program runs is > > probably because you have a class (static) variable initialization > > that requires the class to be loaded. > Could you, please, tell me what to do? I'm not fluent with RMI. 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. 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. -- Regards, John McGrath [TeamB]
Re: RMI
Author: 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"
Re: RMI
Author: Oliver Young
Date: Tue, 19 Aug 2003 09:00
Date: Tue, 19 Aug 2003 09:00
106 lines
4234 bytes
4234 bytes
Something strange happend with source code formatting so I'm reposting it:
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 app)
}
}
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"
Re: RMI
Author: Oliver Young
Date: Tue, 19 Aug 2003 09:18
Date: Tue, 19 Aug 2003 09:18
18 lines
1924 bytes
1924 bytes
I can't understand this:
This peace of code executes *before* any other code in my app (before main()
or code in a front of code block below):
StopDoryIntf rmi = new StopDoryEngine(this);
Naming.rebind(name, rmi);
Although this peace of the code is in the middle of constructor. (?) If I
put "System.out.println("test");" before this block of the code "test" will
not be printed and previously mentioned exception will occur (it can't be
cougth with try/catch block). If I comment block above then executing starts
from the main() and there is no exception. This behavior (start executing
code from the middle of the procedure) is not very common for modern
languges such as VB, Object Pascal (Delphi), C/C++...
Any comments?
Re: RMI
Author: Oliver Young
Date: Tue, 19 Aug 2003 10:04
Date: Tue, 19 Aug 2003 10:04
4 lines
1287 bytes
1287 bytes
Maybe I've found it. Interface and "stub" class are in the same package
as my app. I tried to move it into it's own package but that didn't worked
too. Where I should put them?
Re: RMI
Author: Oliver Young
Date: Tue, 19 Aug 2003 11:01
Date: Tue, 19 Aug 2003 11:01
3 lines
1336 bytes
1336 bytes
Well, I've fixed it and now it is working very well. I'm happy. :) I did
not add interface into .jar that I was deploying to the RMI server...
Re: RMI
Author: John McGrath [TeamB]
Date: Thu, 21 Aug 2003 04:44
Date: Thu, 21 Aug 2003 04:44
10 lines
1253 bytes
1253 bytes
On 8/19/2003 at 7:01:55 AM, Oliver Young wrote: > Well, I've fixed it and now it is working very well. I'm happy. That is good to hear. -- Regards, John McGrath [TeamB]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads