简体   繁体   English

在tomcat服务器中运行时如何在eclipse中提供相对路径

[英]how to provide relative path in eclipse while running in tomcat server

I wrote java code using REST which retrieves the employee details like id and name from a saved file. 我使用REST编写了Java代码,该代码从保存的文件中检索员工详细信息,例如id和name。 Absolute path is working fine while running the tomcat server, but once i provide relative path tomcat is not finding the file path. 运行tomcat服务器时,绝对路径可以正常工作,但是一旦我提供了相对路径,tomcat便找不到文件路径。 I'm using BufferedReader to read from the file. 我正在使用BufferedReader读取文件。

Eclipse server plugin will compile the java sources into binary class files and put it into a work dir, so the relative path will not working. Eclipse服务器插件会将Java源代码编译为二进制类文件,并将其放入work目录中,因此相对路径将不起作用。 The quickest way to make it work is to put your files into the source directory. 使其生效的最快方法是将文件放入源目录。 Then Eclipse server plugin will copy that file to the classes folder in your work directory. 然后,Eclipse服务器插件会将该文件复制到您的工作目录中的classes文件夹中。 Then you can use relative path to read it. 然后,您可以使用相对路径读取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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