---
title: "获取web应用根目录"
author: "江雨行"
date: "2014-07-16T11:55:49Z"
tags: []
categories: ["非技术"]
slug: "web"
draft: true
lastmod: "2014-07-16T11:55:49Z"
id: 2092691
url: "https://yuxinglab.iteye.com/blog/2092691"
---

```
public static String getWebRootAbsolutePath() {  
        String path = null;  
        String folderPath = Path.class.getProtectionDomain().getCodeSource()  
                .getLocation().getPath();  
        if (folderPath.indexOf("WEB-INF") > 0) {  
            path = folderPath.substring(0, folderPath  
                    .indexOf("WEB-INF/classes"));  
        }  
        return path;  
    }  
```