views:

767

answers:

1

I am trying to write some simple Java web services so we can call Java code from .NET. So far, I got a proof-of-concept working under Glassfish. Pretty straightforward when the IDE does all the work.

Now I'm really bogging down on stuff in Java that should be really simple. For example, I want to externalize my configuration so I can change stuff like connection strings/usernames/application variables/etc without recompiling.

In .NET, you would just stick some strings in the web.config file in the root of the web site and use: ConfigurationManager.AppSettings["whateverIwant"];

I can get java.util.Properties to do what I want (from a standalone client), but I can't figure out where to put the .properties file and how to get the path to it from within the web service.

I need my approach to work within WebSphere Application Server as well. Thanks!

+1  A: 

Application configuration is unfortunately container dependent. In general you access your configuration through JNDI. The approach I've recently used was the following:

  • Make a database available to your app (through JNDI, use the Glassfish database "wizard"). This is part is container dependent.
  • Create an entity bean that deserializes your settings from the database. The simple solution here is to have something like this:
@Entity
public class Setting {
  @Id
  private String name;
  private String value;
  ...
}

Then it's a question of doing em.find(Setting.class, "whateveriwant").getValue(). Alternatively, you could create a single entity bean with all the settings as attributes. Either way, this approach reduces the container dependency to a minimum.