【发布时间】:2015-03-20 21:06:31
【问题描述】:
我已经安装了带有 Web 开发的 Eclipse,并且在下载过程中已经将 Tomcat7 安装到了目录 E:\Eclipse\tomcat7。
当在 Eclipse 中尝试测试程序时,我得到了一个真实路径
C:/Users/user/Documents/eclipseJEEWorkspace/javaWebPages/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/org.example.web/WEB-INF/classes /
作为我的真实路径,而不是我所期望的 E:\Eclipse\tomcat7\webapps\org.example.web/WEB-INF/classes/
1)如何获取servlet的真实路径而不是临时路径...
或者我在 Eclipse 如何使用已安装的服务器方面遗漏了什么?如果是这样,那么我是否必须不断创建 WAR 并一直在重新创建/删除?
这样做的原因是我还试图让 JAVA Servlet 访问比 webapps 更高的路径中的文件。我是 servlet 的新手....
我的开发包括所有引用单个文件 our.properties 的第三方软件,因此很遗憾无法更改结构。
我的目录结构是:
/tomcat
/mycompany
/properties
our.properties //the file we want to access
/*otherfiles
/html
/*not used in this context but to show usage
/javascript
/*not used in this context but to show usage
/webapps
/org.example01.web
/META-INF
/WEB-INF
/org.example02.web
/META-INF
/WEB-INF
/org.example03.web
/META-INF
/WEB-INF
如何告诉我的 Servlet 访问 our.properties 文件?
我已经尝试过 getPath、getResource,但没有开始工作,我怀疑我会很快到达任何地方。
谢谢
【问题讨论】:
标签: java eclipse servlets tomcat7