Minimal RMI server fails at in UnicastRemoteObject constructor
Tom O'Reilly
oreilly@mbari.org
Wed Apr 13 23:35:00 GMT 2005
Hello,
I'm new to gcj, and trying to compile an RMI server to native code on my
Linux (Fedora) workstation. Any help would be greatly appreciated! I am
running gcj version 3.4.2.
My server ("BenchServer") is quite minimal; it extends
UnicastRemoteObject, and implements an interface ("Benchmark") that
contains just one method. The server's constructor first invokes
"super()", which generates an ExceptionInInitializerError, with message
"Operation not allowed".
Here are my build steps:
Compile the BenchServer class with javac, so that we can use gjc to
generate stub/skeleton
javac BenchServer.java
Generate stub:
rmic -v1.2 -d . BenchServer
Convert stub to native code:
gcj -c BenchServer_Stub.class
Compile .java source files to native code:
gcj -c Benchmark.java BenchServer.java
Next, link the objects, specify "main" and "policy" file:
gcj Benchmark.o BenchServer.o
BenchServer_Stub.o --main=BenchServer -Djava.security.policy=policy
The policy file looks like this:
grant {
// Allow everyone access to everything
permission java.security.AllPermission;
};
Now I run the a.out executable, which takes one argument (the host
name):
a.out etna
Setting security manager
Constructing server...
Got Exception: Operation not allowed
Exception in thread "main" java.lang.ExceptionInInitializerError
*** Got java.lang.NoClassDefFoundError: gnu.gcj.runtime.NameFinder
while trying
to print stack trace.
Aborted
Anyone know what is going on? Following is my source code:
// Benchmark.java
import java.rmi.Remote;
import java.rmi.RemoteException;
/** Minimal RMI interface. */
public interface Benchmark extends Remote {
void emptyTest() throws RemoteException;
}
// BenchServer.java
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.Naming;
import java.rmi.server.UnicastRemoteObject;
/** Implementation of minimal RMI server. */
public class BenchServer extends UnicastRemoteObject
implements Benchmark {
public BenchServer() throws RemoteException {
super();
System.out.println("Done with constructor.");
}
public void emptyTest() {
System.out.println("emptyTest()");
}
public static void main(String args[]) {
if (args.length != 1) {
System.err.println("Usage: BenchServer hostname");
return;
}
if (System.getSecurityManager() == null) {
System.out.println("Setting security manager");
System.setSecurityManager(new RMISecurityManager());
}
try {
System.out.println("Constructing server...");
BenchServer server = new BenchServer();
System.out.println("server: " + server);
String url = "//localhost/benchmark1";
System.out.println("Binding server to " + url + "...");
Naming.rebind(url, server);
System.out.println("Benchmark1Impl is bound to " + url);
}
catch (Exception e) {
System.err.println("Got Exception: " + e.getMessage());
e.printStackTrace();
}
}
}
----------------------------------------------
Thomas C. O'Reilly
Monterey Bay Aquarium Research Institute
7700 Sandholdt Road
Moss Landing, California 95039-9644
831-775-1766 (voice)
831-775-1620 (FAX)
oreilly@mbari.org (email)
http://www.mbari.org (World-wide Web)
"The machine does not isolate man from the great mysteries
of nature, but plunges him more deeply into them."
- ANTOINE DE SAINT-EXUPERY
"Wind, Sand, and Stars" (1939)
More information about the Java
mailing list