problem with jndi (java.naming.factory.initial)
imen Jun 22, 2013 7:03 PMHello,
i'm trying to develop a server-client application with EJB and a swing-client.
i'm working with Jboss developper studio and jboss 7.1.1-final
here is my EJB class:
package com.sagem.src;
import javax.ejb.Stateless;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import com.sagem.interfaces.IApplication;
import com.sagem.util.UniqueInstance;
@Stateless
public class Application implements IApplication{
/**
* Launch the application.
*/
public void LaunchApplication(final JFrame frame,JDialog dialog){
if (ControlUniqueInstance(frame)){
frame.setVisible(true);
}
else{
//bloquer toutes les fenêtres
try {
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* contrôle s'il y a une autre instance de l'application qui tourne
* **/
public boolean ControlUniqueInstance(final JFrame Mainform){
final int PORT = 32145;
final String MESSAGE = "nomDeMonApplication";
final Runnable RUN_ON_RECEIVE = new Runnable() {
public void run() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if(Mainform != null) {
System.out.printf("if(MainForm != null) \n");
if(!Mainform.isVisible())
Mainform.setVisible(true);
System.out.printf("if(!MainForm.isVisible()) \n");
Mainform.toFront();
}
}
});
}
};
UniqueInstance uniqueInstance = new UniqueInstance(PORT, MESSAGE, RUN_ON_RECEIVE);
return uniqueInstance.launch();
}
public void KillAppli(){
//débloquer toutes les fenêtres
System.exit(-1);
System.out.println("Kill appli!!!!!!!!!!");
}
}
and this is the interface:
package com.sagem.interfaces;
import javax.ejb.Remote;
import javax.swing.JDialog;
import javax.swing.JFrame;
@Remote
public interface IApplication {
void LaunchApplication(JFrame frame,JDialog dialog);
boolean ControlUniqueInstance(JFrame Mainform);
void KillAppli();
}
and this is my swing client (the part where i invoke the EJB class)
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
Application appli = null;
try {
Main frame = new Main();
/***********************connexion EJB - Invocation de la méthode launch******************************************/
try {
InitialContext context = new InitialContext();
System.out.println("initial context done!!!!!!!!");
appli = (Application) context.lookup("/SGMpack_EJB_Project/Application!com.sagem.interfaces.IApplication");
}
catch (NamingException e)
{e.printStackTrace();}
AlerteInstanceDouble dialog = new AlerteInstanceDouble();
appli.LaunchApplication(frame, dialog);
}
catch (Exception e) {e.printStackTrace();}
}
});
};
i placed my jndi.properties file under the source package of my client
here is it's content:
java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
java.naming.provider.url=remote://localhost:4447
java.naming.security.principal=remote
java.naming.security.credentials=testpassword
when i run my application i'm getting the following error:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.sagem.FormInit.Main.main(Main.java:42)