-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I am currently testing Oracle's Weblogic Server with our application. I have deployed our app, but it crashes when it tries to do this:
String xmlFileName = Executions.getCurrent().getDesktop().getWebApp().getRealPath("/WEB-INF/menus.xml"); File xmlFile = new File(xmlFileName);
The Java crash is this:
java.lang.NullPointerException java.io.File.(File.java:222)
And points to the new File line...
Any ideas on how to fix this? This code works fine on Tomcat, OC4J and GlassFish.
Thanks!
You shouldn't use real paths in a production environment. According to the javadoc for ServletContext.getRealPath() (the java equivalent for WebApp.getRealPath()) :
getRealPath
String getRealPath(String path)
Returns a String containing the real path for a given virtual path. For example, the path "/index.html" returns the absolute file path on the server's filesystem would be served by a request for "http://host/contextPath/index.html", where contextPath is the context path of this ServletContext..
The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).
In a production environment you would normally use a war file, either standlone or enclosed in an ear file. You're surely deploying such a file in your weblogic test.
Thanks for the reply cvarona - yes we are deploying the app as an ear file.
This app has a lot of legacy code in it...
I did manage to get this to work by doing the following:
ServletContext serv = (ServletContext)Sessions.getCurrent().getWebApp().getNativeContext(); InputStream xmlFile = serv.getResourceAsStream("/WEB-INF/menus.xml");
Also I have just found out that you can enable an option within Weblogic to get getRealPath to work:
Home > Domains > Web Applications, tick Archived Real Path and restart the server - done :)
Asked: 2012-02-08 02:14:53 +0800
Seen: 333 times
Last updated: Feb 09 '12