简体   繁体   中英

Application and module name though JNDI in WebSphere 7

I have an EAR application in a cell with two web modules, each web module has a servlet.

I want to get through JNDI the application and module name when I request each servlet.

I have tried with:

String applicationName = (String) new InitialContext()
    .lookup("java:app/AppName");

String moduleName = (String) new InitialContext()
    .lookup("java:module/ModuleName");

Did't work. app and module are not found in java: .

I found this example in a webpage, maybe this works for WebSphere 8 but not for 7.

I tried to found an entry with the app or module name in java:comp/env but I didn't found any.

  • How could I get the application name from the Application Server ?
  • And the module name ?
  • There is a better way than though JNDI ?

Thanks in advance.

One way I can think of for application level would be to specify an <env-entry> in the web.xml of your application. Websphere will ask you to specify the value on deployment but it will use whatever you put in web.xml as the default.

For example:

<env-entry>
    <env-entry-name>AppName</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>MyApp</env-entry-value>
</env-entry>

Then you can look this value up through JNDI using java:comp/env/AppName .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM