提交 | 用户 | 时间
|
71e81e
|
1 |
package cn.stylefeng.guns.workflow.core.util; |
懒 |
2 |
|
|
3 |
import org.springframework.web.context.request.RequestContextHolder; |
|
4 |
import org.springframework.web.context.request.ServletRequestAttributes; |
|
5 |
|
|
6 |
import javax.servlet.http.HttpServletRequest; |
|
7 |
import java.io.File; |
|
8 |
|
|
9 |
/** |
|
10 |
* 路径工具类 |
|
11 |
* |
|
12 |
* @author fengshuonan |
|
13 |
* @Date 2019/8/7 23:14 |
|
14 |
*/ |
|
15 |
public class PathUtil { |
|
16 |
|
|
17 |
/** |
|
18 |
* 获取Projectpath |
|
19 |
* |
|
20 |
* @return |
|
21 |
*/ |
|
22 |
public static String getProjectpath() { |
|
23 |
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
24 |
String path = request.getServletContext().getRealPath("/").replaceAll("%20", " ").replaceAll("file:/", "").trim(); |
|
25 |
return path; |
|
26 |
} |
|
27 |
|
|
28 |
/** |
|
29 |
* 获取Classpath |
|
30 |
* |
|
31 |
* @return |
|
32 |
*/ |
|
33 |
public static String getClasspath() { |
|
34 |
String path = (String.valueOf(Thread.currentThread().getContextClassLoader().getResource(""))).replaceAll("file:/", "").replaceAll("%20", " ").trim(); |
|
35 |
if (path.indexOf(":") != 1) { |
|
36 |
path = File.separator + path; |
|
37 |
|
|
38 |
} |
|
39 |
//path = "H:\\"; //当项目以jar、war包运行时,路径改成实际硬盘位置 |
|
40 |
return path; |
|
41 |
} |
|
42 |
|
|
43 |
} |