Could not find or load main class

1

I recently formatted my computer and am having trouble running my java programs.

I'm using linux mint and the settings are as follows:

java -version

java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

echo $ PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin

echo $ JAVA_HOME

/usr/lib/jvm/java-8-oracle

and $ CLASSPATH is empty.

I can compile the programs in a good way and generate the .class files, but when I run the java server command I always get the following error:

  

Error: Could not find or load main class   Server

What should I do to be able to run my programs through the terminal?

The command I use in the shell is:

 ~$javac *.java
 ~$java Servidor

The class I am trying to execute is as follows:

Server.java

    package helloWorld;

    import java.rmi.Remote;
    import java.rmi.registry.Registry;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;

    public class Servidor implements InterfaceObjeto{

    // A chamada do construtor serve para criar os stubs
    public Servidor() {} 

    public String sayHello(){
        return "Hello, World RMI";
    }

    public static void main(String[] args) {

        try{

            // cria e exporta o objeto remoto
            Servidor objeto = new Servidor();
            InterfaceObjeto stub = (InterfaceObjeto) UnicastRemoteObject.exportObject( objeto, 0);

            // registra o objeto com rmi registry
            Registry registro = LocateRegistry.getRegistry();
            registro.bind("interfaceObjeto", stub);

            System.err.println("Servidor pronto");

        }   catch (Exception e) {
            System.err.println("Server exception: " + e.toString());
            e.printStackTrace();
        }


    }
}

InterfaceObject.java

package helloWorld;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface InterfaceObjeto extends Remote{
    public String sayHello() throws RemoteException;
}

Client.java

package helloWorld;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Cliente {

    private Cliente(){}

    public static void main(String[] args) {

        String host = (args.length < 1) ? null : args[0];

        try{

            Registry registro = LocateRegistry.getRegistry(host);
            InterfaceObjeto stub = (InterfaceObjeto)     registro.lookup("InterfaceObjeto");
            String resposta = stub.sayHello();
            System.out.println("resposta: " + resposta);

        } catch (Exception e) {
                System.err.println("Client exception: " +  e.toString());
                e.printStackTrace();
            }
    }
}

When I run the file through netbeans I get the following error:

Server exception: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: helloWorld.InterfaceObjeto
    
asked by anonymous 15.10.2016 / 18:29

0 answers