Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hey!

Ich habe wie man sich sicher denken kanne in Problem mit einem RMI-Callback Testprogramm.

Ich glaube, dass mein Quellcode soweit richtig ist und ich nur probleme mit der policy habe, aber ich bin mir nicht sicher.

Hier der Quellcode von meinem Minibeispiel.

Client:



// Client


import java.io.Serializable;

import java.net.MalformedURLException;

import java.rmi.Naming;

import java.rmi.NotBoundException;

import java.rmi.RMISecurityManager;

import java.rmi.RemoteException;

import java.rmi.server.UnicastRemoteObject;


public class Client implements ClientInterface, Serializable {


    private static final long serialVersionUID = 4099187184648337776L;

    public ServerInterface server;

    public static Client c;


    public Client() {

	super();

	if(System.getSecurityManager() == null){

	    System.setSecurityManager(new RMISecurityManager());

	}

	try {

	    System.out.println("Client gestartet!");


	    UnicastRemoteObject.exportObject(this, 0);

	} catch (Exception e) {

	    e.printStackTrace();

	}

    }


    public void setGeaendert() throws RemoteException {

	try {

	    System.out.println("Neuer Text!: " + server.getText());

	} catch (RemoteException e) {

	    e.printStackTrace();

	}

    }


    public static void main(String[] args) {

	c = new Client();

	try {

	    c.server = (ServerInterface) Naming.lookup("server");

	    c.server.reg((ClientInterface) c);

	    c.server.setAnders("Geändert?");

	} catch (RemoteException e) {

	    e.printStackTrace();

	} catch (MalformedURLException e) {

	    e.printStackTrace();

	} catch (NotBoundException e) {

	    e.printStackTrace();

	}

    }

}


ClientInterface:


// ClientInterface


import java.rmi.Remote;

import java.rmi.RemoteException;


public interface ClientInterface extends Remote {

    public void setGeaendert() throws RemoteException;

}


Server:


// Server


import java.rmi.Naming;

import java.rmi.RMISecurityManager;

import java.rmi.RemoteException;

import java.rmi.registry.LocateRegistry;

import java.rmi.registry.Registry;

import java.rmi.server.UnicastRemoteObject;


public class Server extends UnicastRemoteObject implements ServerInterface {


    private static final long serialVersionUID = 4273340694886491827L;

    public String s = "unverändert!";

    public ClientInterface c;


    public Server() throws RemoteException {

	super();

	if (System.getSecurityManager() == null) {

	    System.setSecurityManager(new RMISecurityManager());

	    System.err.println(System.getSecurityManager());

	}

    }


    public void setAnders(String s) throws RemoteException {

	this.s = s;

	if (c != null)

	    c.setGeaendert();

    }


    public String getText() throws RemoteException {

	return s;

    }


    public void reg(ClientInterface c) throws RemoteException {

	this.c = c;

    }


    public static void main(String[] args) {

	try {

	    Server s = new Server();

	    LocateRegistry.createRegistry(Registry.REGISTRY_PORT);

	    Naming.rebind("server", s);

	    System.out.println("Server hochgefahren!");

	} catch (Exception e) {

	    e.printStackTrace();

	}

    }

}


ServerInterface:




import java.rmi.Remote;

import java.rmi.RemoteException;


public interface ServerInterface extends Remote {

    public void setAnders(String s) throws RemoteException;


    public String getText() throws RemoteException;


    public void reg(ClientInterface c) throws RemoteException;

}


Und zuguterletzt meine Policy:


grant { 

	permission java.net.SocketPermission "*:1024-65535", "connect,accept,resolve";

	permission java.security.AllPermission "","";  

};


Wenn ich den Server starten möchte bekomme ich folgenden Fehler:

Exception in thread "main" java.lang.NoClassDefFoundError: Server

Caused by: java.lang.ClassNotFoundException: Server

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

Could not find the main class: Server. Program will exit.

Wer weiß wo mein Fehler liegt?

Danke schon mal :confused:

Deine Server Klasse wird nun mal nicht gefunden

Phil

Und was muss ich tun damit sie gefunden wird?

Schon geschaft, keine Antworten mehr nötig.

Hallo,

ich bin in diesem Forum Zonbléou. Ich habe eine Frage bzgl. Java, Jni und c dlls. Vielleicht kennst Du dich mit dem Thema um mir zu helfen? Oder jemand der sich mit dem Thema kennt um meine Frage weiterzuleiten?

Vielen Dank.

Zonbléou

Welche Frage denn?

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.