Question

My WAR is deploying fine in TomEE under the correct context root "/myApp" so that I can go to http://localhost:8080/myApp

I have some static files under: /myApp/WEB-INF/files

From looking at the exploded WAR the files are definitely there. My problem is when in code I have written servletContext.getResource("/WEB-INF/files/MyFile.json")I am getting an error that the file is not found because it appears the actual path in the logs is: /localhost/myApp/WEB-INF/files/MyFile.json

This code was actually working when I had the app in a regular tomcat server, in Google App Engine and even in WebSphere 7. In TomEE I am NOT deploying the app under webapps but under wtpwebapps. I've done searches for context configuration but most of those deal with making the app have a context root of "" (making it the root app).

I can write some code to remove the "/localhost" part of the URL but WHY is it being placed in there?

Was it helpful?

Solution

That looks like one of Tomcat's internal jndi URLs which takes the form:

jndi:/hostname/contextPath/pathInWebApp

It looks like you have found a TomEE bug.

OTHER TIPS

I had the same problem, trying to access the log4j.properties file inside the WEB-INF folder. It worked in my local tomcat which is tomcat 8 but failed with the FileNotFoundException on the production server, which runs tomcat 7. So it's not TomEE. I ended up doing this to make it work:

String filePath = context.getRealPath("/") + "/WEB-INF/config/log4j.properties";

That gives me the full path. In my case it was

/home/tomcat/tomcat7/webapps/MY-APPLICATION
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top