JavaWeb Maven 项目获取前台和后台根目录

获取前台根目录(webapp目录)

public static String getClasspath(){
		String path = (String.valueOf(Thread.currentThread().getContextClassLoader().getResource(""))+"../../").replaceAll("file:/", "").replaceAll("%20", " ").trim();	
		if(path.indexOf(":") != 1){
			path = File.separator + path;
		}
		return path;
	}

获取后台根目录(src/main/resources 和  src/main/java)

public static String getClassResources(){
		String path =  (String.valueOf(Thread.currentThread().getContextClassLoader().getResource(""))).replaceAll("file:/", "").replaceAll("%20", " ").trim();	
		if(path.indexOf(":") != 1){
			path = File.separator + path;
		}
		return path;
	}

猜你喜欢

转载自blog.csdn.net/NRlovestudy/article/details/86228545
今日推荐