users@javaee-spec.java.net

[javaee-spec users] Re: Persistent application configuration

From: Pete Muir <pmuir_at_bleepbleep.org.uk>
Date: Mon, 30 Jul 2012 12:38:21 +0100

On 29 Jul 2012, at 04:56, Craig Ringer wrote:

>>> A JNDI access wrapper isn't exactly hard to write where injection isn't available, though it does require the user to understand JNDI - something that's obvious to you and is now obvious to my, but I assure you is not obvious when learning.
>> What would be obvious when learning?
>>
>> I'm not sure Preferences is obvious; most people don't even know about it.
> Good question. Maybe I phrased that poorly. Not necessarily obvious (that's what the docs and tutorials are for) so much as simple to use for basic purposes without a good understanding of how they work.
>
> When learning EE during the EE 5-to-6 transition period I found JNDI confusing because the name syntax varied from place to place (now mostly fixed), the java: prefix appeared to be significant but optional, portable names only work in some places, etc. I'm still muddy about some areas of JNDI. I find it one of the more confusing parts of Java EE. This may shine more light on my intellect and reading/comprehension skills than on EE, but nonetheless may be informative because it could indicate an area where learning could be made easier.
>
> One answer may well be to use JNDI and env entries (with app-setting extensions) - and tweak the JavaDoc and tutorials. If the docs provide simple examples of how it works in common use cases or references to those examples, so it's simple to just get going with the basics, it'd be a lot more accessible. Have the @Resource docs mention different ways an env entry can be set, for example.
>
> It may be worth reading this: http://docs.oracle.com/javaee/6/api/javax/annotation/Resource.html while doing your best to think about what a newbie would know - or not know.
>
> Maybe the issue is just that it's hard to get started. You need to know how it all fits together, which descriptors accept env entries, etc.
>
> As for not knowing about Preferences: Most EE devs certainly don't, because it isn't very useful in EE, it's never referred to in the docs or tutorials, etc. Many SE devs don't know about JNDI or EJBs either. If it were useful and documented for use in an EE context, they'd learn about it through the usual channels - tutorials, blogs, training, "what's new" guides, etc. I'm not saying it's the best answer, just that being unfamiliar isn't a big barrier. After all, CDI was not only unfamiliar but nonexistent before EE 6, but is now widespread.

Whilst we are talking about config, I'll throw in what we've been looking at in DeltaSpike, which is the place lots of us collaborate on CDI extensions.

http://incubator.apache.org/deltaspike/features.html

It you take a look at @ConfigProperty (at the bottom), you'll see that it provides a simple, checked, way to inject strings from properties files. This doesn't solve the problem of deploying configuration outwith the ear/war, however it does provide a nice way to access your properties, and were Java EE to standardize a way to deploy properties outwith the deployment, could be used to access them.