tags:

views:

720

answers:

4

I am deploying an EAR file to the IBM WebSpehre server 6.1 - I want to be able to access the EAR application name which is stored in the deployment file under 'display-name'. Looking through stack overflow posts on related subjects, I've been able to gather that this is possible via the Java MBean API - or IBM's WAS API - Problem is I cannot find a place where these API lists are summarized, i.e. cannot figure out which one to begin looking at. I could hardcode the WAS install location and find the file by looking in the 'installedApps' directory, but this is not dynamic.

Does anyone have any experience working with these APIs? Any other way to dynamically find the deployed EAR's display name?

EDIT - I should add that the reason I would like this information is to dynamically load our properties files - that are named by the following convention "EARAppName.properties" - so you see there IS a reasonable 'rationale' behind desiring this information in my application

EDIT 2 - I should also note that this app will always be deployed on a WAS - but in the case that it isnt, a generic non-proprietary solution would be preferred, but not necessary at this moment.

EDIT 3 - What I want to accomplish: Is there a way to dynamically find the deployed EAR's display name from within the application code?

A: 

That is not for your application to know as such, but for EAR-handling tools, including the application server.

Thorbjørn Ravn Andersen
So is there a way then? Java has a way to find this information regarding classes and methods, via reflection, should there not also be a way to discover the EAR name?
Matt1776
+2  A: 

Not a direct answer but wouldn't it be simpler to use an hard coded name for the properties file? After all, it seems to make sense for a given application to be aware of what file to load. Writing code to read the display-name in a deployment descriptor sounds odd (especially since you, as Application Component Provider, shouldn't rely on something owned by the Application Assembler).

Pascal Thivent
I completely agree - never said the request 'made sense' :) I am trying to come up with a more dynamic formula - as I enjoy dynamic solutions to configuration OR convention.
Matt1776
A: 

If the whole reason for this objective is reading properties files, then I would recommend a different approach.

Use WebSphere Shared Library.

http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/tcws_sharedlib.html

For each deployed EAR have a separate directory containing properties files that needs to be accessed by that EAR.

Create shared library entry for each directory containing properties file.

From EAR create shared library reference to required shared library.

.

However below links may be of some help to you for your approach:

Managing applications through programming

Interface AppManagement

Gladwin Burboz
This might just be the right path to coming up with a dynamic solution. Not exactly what I was looking for but close enough for 'rock and roll' - thank you.
Matt1776
Another issue you will face is managing various property files for each EAR and environments (Dev/QA/Prod, etc.)
Gladwin Burboz
A: 

Hello,

I am trying to accomplish the same thing here. I am trying to locate at runtime the ApplicationName found in the META-INF/application.xml.

We use this AppName in our Log4J File Appender to create a proper log file name base on the Application currently logging. We have lots of programmers and lots of App and we need to enforce some convention in a framework.

I whish I could simply call:

InputStream in = new MyObject().getClass().getResourceAsStream(“META-INF/application.xml”);

I also tried to change the classloader to ‘PARENT_LAST/FIRST’ and ‘Single ClassLoader’ but it does not work.

I could locate the application.xml on filesystem relative to my war file but I am not sure it would work all the time.

Is the JMX Api realy the only way?

Aerosteak