org.apache.commons.lang3

## Class ClassPathUtils

- java.lang.Object
- - org.apache.commons.lang3.ClassPathUtils

-     public class ClassPathUtils
      extends Object

  Operations regarding the classpath.

  The methods of this class do not allow `null` inputs.

  Since:
    3.3

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClassPathUtils()` `ClassPathUtils` instances should NOT be constructed in standard programming.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `packageToPath(String path)` Converts a package name to a Java path ('/').
    `static String` | `pathToPackage(String path)` Converts a Java path ('/') to a package name.
    `static String` | `toFullyQualifiedName(Class<?> context, String resourceName)` Returns the fully qualified name for the resource with name `resourceName` relative to the given context.
    `static String` | `toFullyQualifiedName(Package context, String resourceName)` Returns the fully qualified name for the resource with name `resourceName` relative to the given context.
    `static String` | `toFullyQualifiedPath(Class<?> context, String resourceName)` Returns the fully qualified path for the resource with name `resourceName` relative to the given context.
    `static String` | `toFullyQualifiedPath(Package context, String resourceName)` Returns the fully qualified path for the resource with name `resourceName` relative to the given context.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ClassPathUtils

          public ClassPathUtils()

      `ClassPathUtils` instances should NOT be constructed in standard programming. Instead, the class should be used as `ClassPathUtils.toFullyQualifiedName(MyClass.class, "MyClass.properties");`.

      This constructor is public to permit tools that require a JavaBean instance to operate.

  - ### Method Detail

    - #### packageToPath

          public static String packageToPath(String path)

      Converts a package name to a Java path ('/').
      Parameters:
        `path` - the source path.
      Returns:
        a package name.
      Throws:
        `NullPointerException` - if `path` is null.
      Since:
        3.13.0

    - #### pathToPackage

          public static String pathToPackage(String path)

      Converts a Java path ('/') to a package name.
      Parameters:
        `path` - the source path.
      Returns:
        a package name.
      Throws:
        `NullPointerException` - if `path` is null.
      Since:
        3.13.0

    - #### toFullyQualifiedName

          public static String toFullyQualifiedName(Class<?> context,
                                                    String resourceName)

      Returns the fully qualified name for the resource with name `resourceName` relative to the given context.

      Note that this method does not check whether the resource actually exists. It only constructs the name. Null inputs are not allowed.

           ClassPathUtils.toFullyQualifiedName(StringUtils.class, "StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties"

      Parameters:
        `context` - The context for constructing the name.
        `resourceName` - the resource name to construct the fully qualified name for.
      Returns:
        the fully qualified name of the resource with name `resourceName`.
      Throws:
        `NullPointerException` - if either `context` or `resourceName` is null.

    - #### toFullyQualifiedName

          public static String toFullyQualifiedName(Package context,
                                                    String resourceName)

      Returns the fully qualified name for the resource with name `resourceName` relative to the given context.

      Note that this method does not check whether the resource actually exists. It only constructs the name. Null inputs are not allowed.

           ClassPathUtils.toFullyQualifiedName(StringUtils.class.getPackage(), "StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties"

      Parameters:
        `context` - The context for constructing the name.
        `resourceName` - the resource name to construct the fully qualified name for.
      Returns:
        the fully qualified name of the resource with name `resourceName`.
      Throws:
        `NullPointerException` - if either `context` or `resourceName` is null.

    - #### toFullyQualifiedPath

          public static String toFullyQualifiedPath(Class<?> context,
                                                    String resourceName)

      Returns the fully qualified path for the resource with name `resourceName` relative to the given context.

      Note that this method does not check whether the resource actually exists. It only constructs the path. Null inputs are not allowed.

           ClassPathUtils.toFullyQualifiedPath(StringUtils.class, "StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties"

      Parameters:
        `context` - The context for constructing the path.
        `resourceName` - the resource name to construct the fully qualified path for.
      Returns:
        the fully qualified path of the resource with name `resourceName`.
      Throws:
        `NullPointerException` - if either `context` or `resourceName` is null.

    - #### toFullyQualifiedPath

          public static String toFullyQualifiedPath(Package context,
                                                    String resourceName)

      Returns the fully qualified path for the resource with name `resourceName` relative to the given context.

      Note that this method does not check whether the resource actually exists. It only constructs the path. Null inputs are not allowed.

           ClassPathUtils.toFullyQualifiedPath(StringUtils.class.getPackage(), "StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties"

      Parameters:
        `context` - The context for constructing the path.
        `resourceName` - the resource name to construct the fully qualified path for.
      Returns:
        the fully qualified path of the resource with name `resourceName`.
      Throws:
        `NullPointerException` - if either `context` or `resourceName` is null.

Copyright © 2001–2023 The Apache Software Foundation. All rights reserved.