{"id":28496048,"url":"https://github.com/sonarsource/sonar-classloader","last_synced_at":"2025-07-02T10:31:08.174Z","repository":{"id":27998641,"uuid":"31492858","full_name":"SonarSource/sonar-classloader","owner":"SonarSource","description":"Toolbox for Java classloaders","archived":false,"fork":false,"pushed_at":"2025-02-07T14:04:57.000Z","size":81,"stargazers_count":19,"open_issues_count":0,"forks_count":7,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-06-08T11:51:24.831Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mauro-idsia/blip","license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SonarSource.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-01T10:06:22.000Z","updated_at":"2025-05-21T14:31:20.000Z","dependencies_parsed_at":"2022-09-09T06:24:00.215Z","dependency_job_id":"67baa4cf-f5ec-4b20-b815-29f2e02c7408","html_url":"https://github.com/SonarSource/sonar-classloader","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/SonarSource/sonar-classloader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SonarSource%2Fsonar-classloader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SonarSource%2Fsonar-classloader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SonarSource%2Fsonar-classloader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SonarSource%2Fsonar-classloader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SonarSource","download_url":"https://codeload.github.com/SonarSource/sonar-classloader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SonarSource%2Fsonar-classloader/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263120603,"owners_count":23416851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-08T11:38:30.441Z","updated_at":"2025-07-02T10:31:08.130Z","avatar_url":"https://github.com/SonarSource.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Toolbox for Java Classloaders\n\nSonar Classloader is a toolbox for creating Java 7+ classloaders. It's inspired from projects [Codehaus Classworlds][classworlds] and [Plexus Classworlds][plexus]. It is not coupled with SonarQube and can be used without any third-party dependencies.\n\nThis library is available under GNU LGPLv3.\n\n## Maven Dependency\n\n    \u003cdependency\u003e\n      \u003cgroupId\u003eorg.sonarsource.classloader\u003c/groupId\u003e\n      \u003cartifactId\u003esonar-classloader\u003c/artifactId\u003e\n      \u003cversion\u003e1.1\u003c/version\u003e\n    \u003c/dependency\u003e\n\n## Usage\n\n#### Build classloader\n\nCreate a classloader based on system classloader.\n\n```java\nClassloaderBuilder builder = new ClassloaderBuilder();\nMap\u003cString, ClassLoader\u003e classloaders = builder\n  .newClassloader(\"the-cl\")\n  .addURL(\"the-cl\", jarFile)\n  .addURL(\"the-cl\", directory)\n  .build();\n\n// this classloader can load only JRE and the resources contained in jarFile and directory. \nClassLoader c = classloaders.get(\"the-cl\");\n```\n\nIt's also possible to create a classloader based on another one:\n\n```java\nClassloaderBuilder builder = new ClassloaderBuilder();\nMap\u003cString, ClassLoader\u003e classloaders = builder\n  .newClassloader(\"the-cl\", otherClassloader)\n  .addURL(\"the-cl\", jarFile)\n  .build();\n\n// this classloader can load the resources of JRE, jarFile and otherClassloader. \nClassLoader cl1 = classloaders.get(\"cl1\");\n```\n\n#### Hierarchy of classloaders\n\n```java\nClassloaderBuilder builder = new ClassloaderBuilder();\nMap\u003cString, ClassLoader\u003e classloaders = builder\n  .newClassloader(\"the-parent\")\n  .addURL(\"the-parent\", parentJar)\n  \n  .newClassloader(\"the-child\")\n  .addURL(\"the-child\", childJar)\n  .setParent(\"the-child\", \"the-parent\", Mask.ALL)\n  \n  .newClassloader(\"the-grand-child\")\n  .setParent(\"the-grand-child\", \"the-child\", Mask.ALL)\n  // can be parent-first or self-first ordering strategy. Default is parent-first.\n  .setLoadingOrder(\"the-grand-child\", LoadingOrder.SELF_FIRST)\n  \n  .build();\nClassLoader parent = classloaders.get(\"the-parent\");\nClassLoader child = classloaders.get(\"the-child\");\nClassLoader grandChild = classloaders.get(\"the-grand-child\");\n```\n\nImporting classes and resources from sibling classloaders allows to convert the standard tree of classloaders to a graph a classloaders.\n\n```java\nClassloaderBuilder builder = new ClassloaderBuilder();\n// build 4 classloaders. \"the-child\" searches for resources from sibling1, sibling2, the-parent then itself.\nMap\u003cString, ClassLoader\u003e classloaders = builder\n  .newClassloader(\"the-parent\")\n  .newClassloader(\"sibling1\")\n  .newClassloader(\"sibling2\")\n  .newClassloader(\"the-child\")\n  .setParent(\"the-child\", \"the-parent\", Mask.ALL)\n  .addSibling(\"the-child\", \"sibling1\", Mask.ALL)\n  .addSibling(\"the-child\", \"sibling2\", Mask.ALL)\n  .build();\n```\n\n#### Masks\n\nA mask restricts access of a classloader to some resources and classes. By default there are no restrictions.\n \nA mask is based on inclusion and exclusion patterns. Format is file path separated by slashes, for example \"org/foo/Bar.class\" or \"org/foo/config.xml\". Wildcard patterns are not supported. Directories must end with slash, for example \"org/foo/\" for excluding package org.foo and all its sub-packages.\n\nMasks can be defined on parent-child and sibling relations.\n\n```java\n// all the resources/classes of classloader 'b' are visible from 'a', except org/foo/** resources.\nClassloaderBuilder builder = new ClassloaderBuilder();\nMap\u003cString, ClassLoader\u003e classloaders = builder\n  .newClassloader(\"a\")\n  .newClassloader(\"b\")\n  .addSibling(\"a\", \"b\", Mask.builder().exclude(\"org/foo/\").build())\n  .build();\n```\n\nWhen the same patterns are defined multiple times for each usage of a classloader, then the patterns can be declared once on the targetted classloader.\n\n```java\n// classloader 'a' exports only the resources/classes \"org/a/api/\" but not other internal classes. \nClassloaderBuilder builder = new ClassloaderBuilder();\nMap\u003cString, ClassLoader\u003e classloaders = builder\n  .newClassloader(\"a\")\n  .setExportMask(Mask.builder().include(\"org/a/api/\").build())\n  .newClassloader(\"b\")\n  .newClassloader(\"c\")\n  .addSibling(\"b\", \"a\", Mask.ALL)\n  .addSibling(\"c\", \"a\", Mask.ALL)\n  .build();\n```\n\nThis is equivalent of:\n\n```java\nClassloaderBuilder builder = new ClassloaderBuilder();\nMap\u003cString, ClassLoader\u003e classloaders = builder\n  .newClassloader(\"a\")\n  .newClassloader(\"b\")\n  .newClassloader(\"c\")\n  .addSibling(\"b\", \"a\", Mask.builder().include(\"org/a/api/\").build())\n  .addSibling(\"c\", \"a\", Mask.builder().include(\"org/a/api/\").build())\n  .build();\n```\n\n## License\n\n    Copyright (C) 2015 SonarSource\n    \n    This program is free software; you can redistribute it and/or\n    modify it under the terms of the GNU Lesser General Public\n    License as published by the Free Software Foundation; either\n    version 3 of the License, or (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n    Lesser General Public License for more details.\n\n    You should have received a copy of the GNU Lesser General Public\n    License along with this program; if not, write to the Free Software\n    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02\n\n[classworlds]: http://classworlds.codehaus.org\n[plexus]: https://github.com/sonatype/plexus-classworlds\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonarsource%2Fsonar-classloader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonarsource%2Fsonar-classloader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonarsource%2Fsonar-classloader/lists"}