1

I am trying to improve my understanding of remote EJB invocation.

I have code like this working, which does a remote JNDI lookup on my server:

private InitialContext jndiContext;    
private AdderBeanRemote bean1;

Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("org.omg.CORBA.ORBInitialHost", "10.0.0.99");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
jndiContext = new InitialContext(props);
bean1 = (AdderBeanRemote) jndiContext.lookup("com.suspectclass.sgifford.test8bean.AdderBeanRemote");

But that seems way to complicated, and hardcodes a lot of application-specific data into my application; for example, if I wanted to use a different server or renumber my network, I would have to modify my application then recompile and redeploy.

I have seen some solutions that use "jndi.properties", but so far I haven't gotten any to work, and at any rate this would still require me to recompile and redeploy to change anything.

Is there a simpler way of doing this that doesn't require hardcoding my network details into my app? Or is this the best I can do?

Thanks!

-----Scott.

sgifford
  • 53
  • 3

1 Answers1

0

I think an external .properties file is the way to go to avoid recompilation.

This file could either be outside the packaged .jar as a separate file in the filesystem

or packaged into a "configuration-resources.jar" that you bring onto the classpath. This question covers the basic of reading properties on some different deployment scenarios

If you want to dwelve more into the jndi.properties, read more at oracle, i guess using jndi.properties is more of the recommended way, as you avoid reading properties programatically. But you might reach faster results by just reading a home-made .properties-file from the filesystem.

Community
  • 1
  • 1
Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
  • Thanks, I will have to learn more about the configuration-resources.jar! – sgifford Mar 22 '13 at 19:30
  • I might have mislead you. What i meant was, you could package configuration files into a separate .jar instead of bundling them in your application jar. There is no concept here, its just a name i made up. – Aksel Willgert Mar 22 '13 at 19:32
  • Ah, I see, I googled "configuration-resources.jar" and came up with some hits, so I thought it was a thing. So they would just be a separate JAR inside my application WAR or EAR file? – sgifford Mar 22 '13 at 20:08