System.getProperty("user.dir") 在通过 Web 服务执行时给出 Eclipse 的路径 [英] System.getProperty("user.dir") giving path of eclipse while executing through web service

查看:34
本文介绍了System.getProperty("user.dir") 在通过 Web 服务执行时给出 Eclipse 的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从一个简单的 java 类执行 System.getProperty("user.dir") 时,它给了我正确的路径,如工作区/项目名称.但是,当我在 REST Web 服务的服务方法中编写相同的代码并通过其在 chrome 上的客户端应用程序执行它时,它给了我 eclipse 所在的路径而不是当前目录.有没有办法获取当前工作目录的路径或java文件(服务)所在的路径.我需要这个,因为我想读取一个与 java 文件放在相同路径中的属性文件.

While executing System.getProperty("user.dir") from a simple java class, it gives me correct path like workspace/projectName. But when I write the same code in service method of a REST web service and execute it through its client app on chrome, it gives me the path where eclipse is located and not the current directory. Is there any way to get path of current working directory or the path where java file(service) is located. I need this because I want to read a property file which is placed in same path as the java file.

推荐答案

我遇到了同样的问题,并通过配置更改解决了它.使用 Run -> Run Configurations 更改 Eclipse 中工作目录的位置.在参数选项卡上选择其他单选按钮并将工作区或任何自定义位置指定为工作目录.

I got the same problem and got it resolved using configuration change. Change the location of working directory in Eclipse using Run -> Run Configurations. On Arguments Tab select Other radio button and specify Workspace or any custom location as a Working directory.

这篇关于System.getProperty("user.dir") 在通过 Web 服务执行时给出 Eclipse 的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆