Skip to content

Instantly share code, notes, and snippets.

@maartenl
Created September 6, 2021 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maartenl/00663f1d1dbaf4dd0792e864a9074e65 to your computer and use it in GitHub Desktop.
Save maartenl/00663f1d1dbaf4dd0792e864a9074e65 to your computer and use it in GitHub Desktop.
Finding out where your classfile resides.
public class ClassTest {
@Test
public void testClassResource() {
URL resource = getClass().getResource("/org/testng/annotations/Test.class");
assertThat(resource).isNotNull();
assertThat(resource.toString()).endsWith("/org/testng/testng/6.13.1/testng-6.13.1.jar!/org/testng/annotations/Test.class");
}
@Test
public void testClassloaderResource() {
URL resource = getClass().getClassLoader().getResource("org/testng/annotations/Test.class");
assertThat(resource).isNotNull();
assertThat(resource.toString()).endsWith("/org/testng/testng/6.13.1/testng-6.13.1.jar!/org/testng/annotations/Test.class");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment