---
title: "获取类所在的classpath绝对路径"
author: "black_angle"
date: "2008-03-27T14:45:00Z"
tags: []
slug: "classpath"
draft: false
lastmod: "2008-03-27T14:45:00Z"
id: 260738
url: "https://black-angle.iteye.com/blog/260738"
---

例：

String path=this.getClass**().getResource("/").toString**()；

在web project下：

在tomcat下获取到的路径是:file:/D:/workspace/techSite/WebRoot/WEB-INF/classes/

直接在java project下：获取到的路径是：file:/D:/workspace/aaa/bin/

说明this.getClass**().getResource("/").toString**()获取的是该类的所在的classpath，暂时的理解