当我在服务器上运行代码时,如何在eclipse中获取Web应用程序目录路径?

时间:2016-12-06 10:39:56

标签: spring-mvc

  URL location = HelloWorldController.class.getProtectionDomain().getCodeSource().getLocation();
        System.out.println(location.getFile());   

它将输出为

  

/C:/Users/MyProjects/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Spring3MVC/WEB-INF/classes /

这里Spring3MVC是我的动态项目名称

但我希望输出为C:\ Users \ Myprojects \ workspace \ Spring3MVC

怎么做?

0 个答案:

没有答案