3
I am programming a simple system, using RMI, to train programming. However I found some problems when creating the file .batch receiving the message on the windows terminal
'rmiregistry' is not recognized as an Internal or External command, operable program or batch file.
I would like to know how I can solve this problem, if necessary I will be sending the code of the program also to be analyzed and see if there are any links
Client class
package Client;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.NotBoundException;
import java.net.MalformedURLException;
import Comum.IntDataHora;
import Comum.IntDataHoraImp;
public class ClienteDataHora
{
public static void main(String[] args)
{
try
{
IntDataHora mensagem = (IntDataHora) Naming.lookup(IntDataHoraImp.getUri());
System.out.println(mensagem.getDatahora());
}
catch(MalformedURLException e)
{
System.out.println("Erro de formação da uri");
}
catch (RemoteException e)
{
System.out.println("Erro de comunicação");
}
catch (NotBoundException e)
{
System.out.println("epa! um erro!");
}
}
}
Interface
package Comum;
public interface IntDataHora
{
public String getDatahora();
}
Implementation of the interface
package Comum;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.Formatter;
public class IntDataHoraImp extends UnicastRemoteObject implements IntDataHora
{
private static String servidor = "localhost";
private static int porta = 1099;
private static String servico = "DataHora";
private int solicitacao = 0;
public static String getUri()
{
String uri = String.format("rmi//%s:%d:%s", servidor,porta,servico);
return uri;
}
public IntDataHoraImp()throws RemoteException
{
super();
}
@Override
public String getDatahora()
{
GregorianCalendar atual = new GregorianCalendar();
SimpleDateFormat formatacao = new SimpleDateFormat("dd' de 'MMMMM' de 'yyyy' - 'HH':'mm'h'");
return formatacao.format(atual.getTime());
}
}
Server class
package Servidor;
import java.rmi.Naming;
import Comum.IntDataHora;
import Comum.IntDataHoraImp;
import java.net.MalformedURLException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ServidorDataHora
{
public ServidorDataHora() throws MalformedURLException
{
try
{
IntDataHora mensagem = new IntDataHoraImp();
mensagem = new IntDataHoraImp();
Naming.rebind(IntDataHoraImp.getUri(), (Remote) mensagem);
} catch (RemoteException ex)
{
System.out.println("Erro:"+ ex);
}
}
}
Do you have the environment variables set ? ex: path environment variables
– Dilnei Cunha
To be honest I don’t think I have. how can I set them up?
– Programmer goblin
is on the link above, where I commented.
– Dilnei Cunha
A
echo %PATH%
shows what?– Victor Stafusa
@Dilneicunha thank you very much, problem solved!
– Programmer goblin
@Luizcarlossimonard kindly post your solution as an answer, maybe help other people!
– Genos