Skip to main content

Reading System Properties from an EJB Bean?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
10 replies [Last post]
lprimak
Offline
Joined: 2006-08-22

Hi,
I have a situation where I am deploying the same application to different server clusters.
I'd like to pass a configuration value to the EJB that's different for each cluster.
I was hoping to use a Glassfish Configuration system property for this task,
but I have not found a way to read a system property from an EJB.
Does anybody know how to do this?

Just to clarify, this is not System.getProperty() that I am talking about,
it's what the Glassfish admin console refers to as 'system properties'

Thanks for your help,
Lenny

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
lprimak
Offline
Joined: 2006-08-22

Just to add, I've tried @Resource injection, but that only works with the ejb-jar file which I do not want to have,
and its also does not serve the purpose of reading system properties from the configuration.
There is actually more that I want to do with this. I need to be able to read other cluster configuration values,
such as port number, the log file location, etc, so I really need access to the cluster/server configuration basically.

Thanks

tmueller
Offline
Joined: 2005-10-31

The system properties from the domain.xml are put into the Java
System.properties, so that they are available via System.getProperty.
Is that not working for you?

Tom

On 3/17/2011 8:48 PM, forums@java.net wrote:
> Just to add, I've tried @Resource injection, but that only works with the
> ejb-jar file which I do not want to have, and its also does not serve the
> purpose of reading system properties from the configuration. There is
> actually more that I want to do with this. I need to be able to read
> other
> cluster configuration values, such as port number, the log file location,
> etc, so I really need access to the cluster/server configuration
> basically.
> Thanks
>

lprimak
Offline
Joined: 2006-08-22

Tom,

As far as I can tell, System,getProperty() only has access to the JVM Options specified via -D command line option,
which can also be accessed via the admin console,
but what I am really looking to access are the cluster's System Properties, which do not show up there.

Thanks!

tmueller
Offline
Joined: 2005-10-31

Maybe there is a difference here between EJBs and other web content.
Hopefully someone from the EJB team can chime in.

I tried a simple web application with the following JSP content:

Environment
<% for (String n : System.getProperties().stringPropertyNames()) {
out.append(n).append("=").append(System.getProperty(n));
out.append("");
out.newLine();
}
%>

I ran:

asadmin create-system-properties --target server foo=bar

and then accessed the application, and the value of the property was
printed by the JSP.

Tom

lprimak
Offline
Joined: 2006-08-22

You are right. When I did it via command line, it got propagated.
I guess the question becomes where should I do this in the Admin GUI?

Thanks!

anilam
Offline
Joined: 2005-03-29

To set the system properties of a cluster, you can go to the cluster
page. There is a properties tab. click on the tab and you will see the
table that shows you the system properties.
eg. if you do %asadmin create-system-properties --target clusterABC foo=bar

You will see it in the System Properties tab of this cluster. (see
attached image)
you can also add system properties there.

Anissa

On 3/18/11 11:26 AM, forums@java.net wrote:
> You are right. When I did it via command line, it got propagated. I
> guess the
> question becomes where should I do this in the Admin GUI? Thanks!
>

tmueller
Offline
Joined: 2005-10-31

System properties can be set at the domain, config, cluster, or instance level.
For example, to set a system property at the config level in the console, select Configurations, select the right configuration, click on System Properties, and click on Add Property. For instances, select the instance and click on the Properties tab.
Tom

lprimak
Offline
Joined: 2006-08-22

Ah, I think I am figuring this out now.

In domain.xml, when executing command create-system-properties,
that creates a <system-property&rt; entry,
but when I am adding it from ths admin console, it creates
that creates a <property&rt; entry, hence it didn't work for me at first.

Is there any way to read the property entry? Those seem to be easier to create :)

anilam
Offline
Joined: 2005-03-29

As mentioned earlier, if you go to the cluster page, and then the
Properties tab -> System Properties page, you can create the system
properties, and it will be written to domain.xml as

This is equivalent to
%asadmin create-system-properties --target clusterABC foo=bar

Anissa.

On 3/18/11 3:13 PM, forums@java.net wrote:
> I am adding it from ths admin console, it creates that creates a
>

mvatkina
Offline
Joined: 2005-04-04

Nothing in EJB container code prohibits you to do that. May be the
properties are not propagated correctly to the clustered instances?

-marina

Tom Mueller wrote:
> Maybe there is a difference here between EJBs and other web content.
> Hopefully someone from the EJB team can chime in.
>
> I tried a simple web application with the following JSP content:
>
> Environment
> <% for (String n : System.getProperties().stringPropertyNames()) {
> out.append(n).append("=").append(System.getProperty(n));
> out.append("");
> out.newLine();
> }
> %>
>
> I ran:
>
> asadmin create-system-properties --target server foo=bar
>
> and then accessed the application, and the value of the property was
> printed by the JSP.
>
> Tom