开发者社区> 问答> 正文

eclipse下开发web项目获取项目路径怎么得不到?

System.out.println(this.getRequest().getServletContext()

             .getRealPath("/")); 

我其实想要得到项目在工作空间下的路径,就是项目的相对路径

我想得到的是 F:AAAAworkspaceDemo_03,以及WebContext下的路径。但是的出来的确实这个很郁闷,之前用的myEclipse开发的用个就可以了不知道为什么用Eclipse却是着。请指点

F:AAAAworkspace.metadata.pluginsorg.eclipse.wst.server.coretmp0wtpwebappsDemo_03

展开
收起
爵霸 2016-06-06 13:30:34 2386 0
1 条回答
写回答
取消 提交回答
  • public class FileTest {
         public static void main(String[] args) throws Exception {       
    
      System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));     
    
      System.out.println(FileTest.class.getClassLoader().getResource(""));        
    
      System.out.println(ClassLoader.getSystemResource(""));        
       System.out.println(FileTest.class.getResource(""));        
       System.out.println(FileTest.class.getResource("/")); //Class文件所在路径  
       System.out.println(new File("/").getAbsolutePath());        
       System.out.println(System.getProperty("user.dir"));    
      }
     } 
    2019-07-17 19:28:21
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Web应用系统性能优化 立即下载
高性能Web架构之缓存体系 立即下载
PWA:移动Web的现在与未来 立即下载

相关镜像