Java tutorial
//package com.java2s; import java.io.File; import java.net.URISyntaxException; import java.net.URL; public class Main { public static File findPom(Class clazz) { try { URL location = clazz.getProtectionDomain().getCodeSource().getLocation(); File classFile = new File(location.toURI()); File root = findPomRoot(classFile); return root != null ? new File(root, "pom.xml") : null; } catch (URISyntaxException e) { throw new RuntimeException(e); } } private static File findPomRoot(File file) { if (file.isDirectory() && new File(file, "pom.xml").exists()) { return file; } if (file.getParentFile() != null) { return findPomRoot(file.getParentFile()); } return null; } }