Class OpenClassPath

java.lang.Object
cloud.opencode.base.classloader.OpenClassPath

public final class OpenClassPath extends Object
OpenClassPath - ClassPath Utilities Facade OpenClassPath - ClassPath 工具门面

Utilities for working with classpath.

用于操作 classpath 的工具。

Features | 主要功能:

  • Get classpath URLs - 获取 classpath URL
  • Convert class name to resource path - 类名转资源路径
  • Find resources - 查找资源

Usage Examples | 使用示例:

// Get classpath URLs
List<URL> urls = OpenClassPath.getClassPathUrls();

// Convert class name to path
String path = OpenClassPath.classNameToResourcePath("com.example.MyClass");
// Returns: "com/example/MyClass.class"

// Find resource
Optional<URL> url = OpenClassPath.findResource("config.yml");

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-classloader V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • getClassPathUrls

      public static List<URL> getClassPathUrls()
      Get all classpath URLs 获取所有 classpath URL
      Returns:
      list of classpath URLs | classpath URL 列表
    • getClassPathEntries

      public static List<Path> getClassPathEntries()
      Get all classpath entries as paths 获取所有 classpath 条目作为路径
      Returns:
      list of classpath paths | classpath 路径列表
    • getClassPath

      public static String getClassPath()
      Get runtime classpath string 获取运行时 classpath 字符串
      Returns:
      classpath string | classpath 字符串
    • classNameToResourcePath

      public static String classNameToResourcePath(String className)
      Convert class name to resource path 将类名转换为资源路径
      Parameters:
      className - fully qualified class name | 完全限定类名
      Returns:
      resource path | 资源路径
    • resourcePathToClassName

      public static String resourcePathToClassName(String resourcePath)
      Convert resource path to class name 将资源路径转换为类名
      Parameters:
      resourcePath - resource path | 资源路径
      Returns:
      class name | 类名
    • packageNameToResourcePath

      public static String packageNameToResourcePath(String packageName)
      Convert package name to resource path 将包名转换为资源路径
      Parameters:
      packageName - package name | 包名
      Returns:
      resource path | 资源路径
    • getPackageResources

      public static List<URL> getPackageResources(String packageName)
      Get all resource URLs for a package 获取包的所有资源 URL
      Parameters:
      packageName - package name | 包名
      Returns:
      list of URLs | URL 列表
    • findResource

      public static Optional<URL> findResource(String resourceName)
      Find single resource 查找单个资源
      Parameters:
      resourceName - resource name | 资源名
      Returns:
      optional URL | 可选的 URL
    • findResources

      public static List<URL> findResources(String resourceName)
      Find all matching resources 查找所有匹配的资源
      Parameters:
      resourceName - resource name | 资源名
      Returns:
      list of URLs | URL 列表
    • resourceExists

      public static boolean resourceExists(String resourceName)
      Check if resource exists on classpath 检查资源是否存在于 classpath
      Parameters:
      resourceName - resource name | 资源名
      Returns:
      true if exists | 存在返回 true
    • classExists

      public static boolean classExists(String className)
      Check if class exists on classpath 检查类是否存在于 classpath
      Parameters:
      className - class name | 类名
      Returns:
      true if exists | 存在返回 true