BAEL-5158: Sample App and Unit test for finding ObjectMapper class in a jar.

This commit is contained in:
ravipathak
2022-01-05 00:56:45 +00:00
parent f93f228c91
commit 496fddbb28
3 changed files with 31 additions and 0 deletions

View File

@@ -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());
}
}

View File

@@ -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"));
}
}