My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Tuesday, January 5, 2010

weblogic: ServletContext.getRealPath doesn't work in older weblogic version

ServletContext.getRealPath only works where war is exploded on the file system in case of weblogic getRealPath always returns null.

You can refer to the CR CR299135 for weblogic version 10 and above.

Use the <show-archived-real-path-enabled> flag to specify that
context.getRealPath() returns the path of the resource from the Server's
internal webapp extraction directory for archived web applications. The
flag can be configured in two ways:
  • At domain level in config.xml. For example:
    <web-app-container>
    <show-archived-real-path-enabled>true
    </show-archived-real-path-enabled>
    </web-app-container>
  • At the web app level in weblogic.xml. For example:
    <container-descriptor>
    <show-archived-real-path-enabled>true
    </show-archived-real-path-enabled>
    </container-descriptor>
    The value of <show-archived-real-path-enabled> set in the web app has
    precedence over the value set at the domain level. The default value of
    this property is false.
    Note that, if this path is used to dynamically copy some content to this
    directory location, the content will end up in the Server's internal web
    app extraction directory. When the web app is recompiled for any reason,
    the web app may be re-extracted and previously copied content will be
    lost.
For versions which are less than 10 and below

use

String rootPath = StringUtils.replace(context.getRealPath(StringUtils.EMPTY), "", "/");

 That's it.

You will no longer see the issue.

Hope this helps some one who struggles with weblogic NOT AGAIN

No comments :