BAEL-5158: Sample App and Unit test for finding ObjectMapper class in a jar.
This commit is contained in:
parent
da600ee93a
commit
a2bd7b50ed
|
@ -8,3 +8,4 @@ This module contains articles about JAR files
|
||||||
- [Importance of Main Manifest Attribute in a Self-Executing JAR](http://www.baeldung.com/java-jar-executable-manifest-main-class)
|
- [Importance of Main Manifest Attribute in a Self-Executing JAR](http://www.baeldung.com/java-jar-executable-manifest-main-class)
|
||||||
- [Guide to Creating and Running a Jar File in Java](https://www.baeldung.com/java-create-jar)
|
- [Guide to Creating and Running a Jar File in Java](https://www.baeldung.com/java-create-jar)
|
||||||
- [Get Names of Classes Inside a JAR File](https://www.baeldung.com/jar-file-get-class-names)
|
- [Get Names of Classes Inside a JAR File](https://www.baeldung.com/jar-file-get-class-names)
|
||||||
|
[Find All Jars Containing Given Class](https://baeldung.com/find-all-jars-containing-given-class/)
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.baeldung.jar;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class JarApp {
|
||||||
|
|
||||||
|
public static String findObjectMapperClass() {
|
||||||
|
Class<ObjectMapper> klass = ObjectMapper.class;
|
||||||
|
URL path = klass.getProtectionDomain().getCodeSource().getLocation();
|
||||||
|
return path.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(findObjectMapperClass());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.baeldung.jar;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class JarAppUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findClassTest(){
|
||||||
|
Assert.assertTrue(JarApp.findObjectMapperClass().endsWith("jackson-databind-2.13.0.jar"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue