diff --git a/core-java-modules/core-java-finding-class/README.md b/core-java-modules/core-java-finding-class/README.md new file mode 100644 index 0000000000..d2ff15449d --- /dev/null +++ b/core-java-modules/core-java-finding-class/README.md @@ -0,0 +1,3 @@ +### Relevant Articles + +[Find All Jars Containing Given Class](https://baeldung.com/find-all-jars-containing-given-class/) \ No newline at end of file diff --git a/core-java-modules/core-java-finding-class/pom.xml b/core-java-modules/core-java-finding-class/pom.xml new file mode 100644 index 0000000000..8930fcdf0c --- /dev/null +++ b/core-java-modules/core-java-finding-class/pom.xml @@ -0,0 +1,30 @@ + + + com.baeldung.jar + core-java-finding-class + 0.1.0-SNAPSHOT + core-java-finding-class + jar + + core-java-modules + com.baeldung.core-java-modules + 0.0.1-SNAPSHOT + + 4.0.0 + + + 8 + 8 + 2.13.1 + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + \ No newline at end of file diff --git a/core-java-modules/core-java-finding-class/src/main/java/com/baeldung/jar/App.java b/core-java-modules/core-java-finding-class/src/main/java/com/baeldung/jar/App.java new file mode 100644 index 0000000000..a19d88e349 --- /dev/null +++ b/core-java-modules/core-java-finding-class/src/main/java/com/baeldung/jar/App.java @@ -0,0 +1,18 @@ +package com.baeldung.jar; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.net.URL; + +public class App { + + public static String findObjectMapperClass() { + Class klass = ObjectMapper.class; + URL path = klass.getProtectionDomain().getCodeSource().getLocation(); + return path.toString(); + } + + public static void main(String[] args) { + System.out.println(findObjectMapperClass()); + } +} diff --git a/core-java-modules/core-java-finding-class/src/test/java/com/baeldung/jar/AppUnitTest.java b/core-java-modules/core-java-finding-class/src/test/java/com/baeldung/jar/AppUnitTest.java new file mode 100644 index 0000000000..1fb57f0f67 --- /dev/null +++ b/core-java-modules/core-java-finding-class/src/test/java/com/baeldung/jar/AppUnitTest.java @@ -0,0 +1,12 @@ +package com.baeldung.jar; + +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +public class AppUnitTest { + + @Test + public void findClassTest(){ + Assert.assertTrue(App.findObjectMapperClass().endsWith("jackson-databind-2.13.1.jar")); + } +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index d9da5a845b..5f4a796213 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -118,6 +118,7 @@ core-java-regex-2 core-java-uuid pre-jpms + core-java-finding-class