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 da600ee93a
commit 83f6ae5d9d
5 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,3 @@
### Relevant Articles
[Find All Jars Containing Given Class](https://baeldung.com/find-all-jars-containing-given-class/)

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>com.baeldung.jar</groupId>
<artifactId>core-java-finding-class</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>core-java-finding-class</name>
<packaging>jar</packaging>
<parent>
<artifactId>core-java-modules</artifactId>
<groupId>com.baeldung.core-java-modules</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<jackson.version>2.13.1</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>
</project>

View File

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

View File

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

View File

@ -118,6 +118,7 @@
<module>core-java-regex-2</module>
<module>core-java-uuid</module>
<module>pre-jpms</module>
<module>core-java-finding-class</module>
</modules>
<dependencyManagement>