# RMI ExportException object already exported



## SilentJ (5. Feb 2007)

Hallo,

Java merkt bei meiner Anwendung an, dass mein UnicastRemoteObject schon exportiert wurde und wirft eine Exception:


```
public static void main(String[] args){
		System.setProperty("javax.net.ssl.keyStore", "xxx");
		System.setProperty("javax.net.ssl.keyStorePassword", "xxx");
		try {
			RMIClientSocketFactory rmiClient = new SslRMIClientSocketFactory();
			System.out.println("Client.");
			RMIServerSocketFactory rmiServer = new SslRMIServerSocketFactory();
			System.out.println("Server.");
			//FileServer fs = new FileServer();
			FileService service = (FileService) UnicastRemoteObject.exportObject(new FileServer(), 0,
						rmiClient, rmiServer);
			Registry registry = LocateRegistry.createRegistry(1099);
			//registry.rebind("FileService", service);
			System.out.println("Service running!");
		}catch(ExportException ee){
			System.err.print(ee.toString());
		}catch (RemoteException e) {
			System.err.println(e.toString());
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
```

Das zu erzeugende Remote-Objekt sieht dabei so aus:

```
public class FileServer 
extends UnicastRemoteObject 
implements FileService {

	public FileServer() throws RemoteException {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = -1942543374809677561L;

	public Dokument createDokument(Dokument dokument) throws RemoteException {
		System.out.println("Dokument created");
		return null;
	}

	public boolean deleteDokument(Dokument dokument) throws RemoteException {
		// TODO Auto-generated method stub
		return false;
	}

	public Dokument readDokument(Dokument dokument) throws RemoteException {
		// TODO Auto-generated method stub
		return null;
	}

	public Dokument updateDokument(Dokument dokument) throws RemoteException {
		// TODO Auto-generated method stub
		return null;
	}

}
```

Und dann kommt das:

[/code]java.rmi.server.ExportException: object already exported
java.rmi.server.ExportException: object already exported
	at sun.rmi.transport.ObjectTable.putTarget(Unknown Source)
	at sun.rmi.transport.Transport.exportObject(Unknown Source)
	at sun.rmi.transport.tcp.TCPTransport.exportObject(Unknown Source)
	at sun.rmi.transport.tcp.TCPEndpoint.exportObject(Unknown Source)
	at sun.rmi.transport.LiveRef.exportObject(Unknown Source)
	at sun.rmi.server.UnicastServerRef.exportObject(Unknown Source)
	at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
	at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
	at de.fileserver.FileServerStarter.main(FileServerStarter.java:27)
	
	
	
	





```
Hilfe! Es liegt definitiv an der exportObject-Anweisung

Michael
```


----------



## SilentJ (5. Feb 2007)

RMI scheint ziemlich wenig nachgefragt zu werden in diesem Forum.

Ein Workaround kann so aussehen, jedenfalls startet der Service:

```
public class FileServer 
extends UnicastRemoteObject 
implements FileService {
	
	private static SslRMIServerSocketFactory serverSocket = null;
	private static SslRMIClientSocketFactory clientSocket = null;

	static{
		System.setProperty("javax.net.ssl.keyStore", "xxx");
		System.setProperty("javax.net.ssl.keyStorePassword", "xxx");
		System.out.println("Statically initialized.");
	}
	
	public FileServer() throws RemoteException {
		super(0,(clientSocket= new SslRMIClientSocketFactory()),
				(serverSocket = new SslRMIServerSocketFactory()));
	}
	
	public void bind(){
		
		try {
			/*RMIClientSocketFactory rmiClient = new SslRMIClientSocketFactory();
			System.out.println("Client.");
			RMIServerSocketFactory rmiServer = new SslRMIServerSocketFactory();
			System.out.println("Server.");*/
			//FileServer fs = new FileServer();
			/*FileService service = (FileService) UnicastRemoteObject.exportObject(this, 2009,
						clientSocket, serverSocket);*/
			Registry registry = LocateRegistry.createRegistry(2004);
			registry.rebind("FileService", this);
			for( String serviceName : registry.list())
			{
				System.out.println(serviceName);
			}
			System.out.println("Service running!");
		}catch(ExportException ee){
			ee.printStackTrace();
			ee.getCause().toString();
		}catch (RemoteException e) {
			System.err.println(e.toString());
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
```

Bleibt nur noch, das mit meinem Spring-Projekt zu verheiraten.


----------

