How do I get the path from where a class is loaded?

This examples shows how to get a path name or location from where our class is loaded.

package org.kodejava.example.lang;

public class CodeSourceLocation {
    public static void main(String[] args) {
        CodeSourceLocation csl = new CodeSourceLocation();

    private void getCodeSourceLocation() {
        // The the location from where the class is loaded.
        System.out.println("Code source location: " +

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you ?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.