eclipse中的tomcat,代码中创建file获取目录与tomcat单独运行获取目录不同的解决办法

提示,此代码所在的都是rest接口(web项目)中,而不是在普通的Test类或者是main方法中

重现:
    @GET
    public Response sayHello(@Context HttpServletRequest request,
            @Context HttpServletResponse response ){
        File file=new File("repository/configuration.xml");
        URI uri = file.toURI();
        System.out.println(uri);
        return Response.ok().status(200).build();
    }


返回结果为:
file:/E:/works/eclipse-jee-mars-2-win32-x86_64/eclipse/repository/configuration.xml

而我要获取的是tomcat下的目录,如我上端代码,直接启动tomcat运行获取到的是:
file:/N:/works/IDE/apache-tomcat-7.0.54-windows-x86/apache-tomcat-7.0.54/bin

那么就要修改配置,让在eclipse中也获取此目录

解决办法:
1、双击Servers下的tomcat

2、将会打开eclipse中的tomcat配置界面,然后点击“Open launch configuration”


3、打开标签页Arguments,选择“Working  directory“为Other,填入如下值:
    N:\works\IDE\apache-tomcat-7.0.54-windows-x86\apache-tomcat-7.0.54\bin
    然后保存即可
如图:


修改过后,再在eclipse中启动tomcat,运行此代码获取到的就是和tomcat运行时获取的目录相同了

file:/N:/works/IDE/apache-tomcat-7.0.54-windows-x86/apache-tomcat-7.0.54/bin
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值