I did a workaround. In pom.xml the application.finalName property is defined to the name the ear will have and is used in build section finalName tag. I have a mbean which is configured via a *-service.xml file deployed in the ear. In there I have an attribute definition like this:
<attribute name="EarName">${application.finalName}</attribute>
Maven will replace the macro with the property value. Then I have a ServiceLocator singleton class which is used by all clients to lookup the services, it has a method like this:
private static String getEarName() {
if(earName == null) {
// This will lookup the name of the ear from our mbean
MBeanServer mBeanServer = MBeanServerLocator.locateJBoss();
try {
earName = (String) mBeanServer.invoke( new ObjectName("com.limetransit.sms:service=LimeManagement"),
"getEarName",
new Object[] {},
new String[] {}
);
} catch(Exception e) {
e.printStackTrace();
}
}
return earName + "/";
}
May not be the most beautiful solution but it works at least...