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

来源:互联网 发布:window.open php 编辑:程序博客网 时间:2024/05/17 01:49
提示,此代码所在的都是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
1 0
原创粉丝点击