Repository navigation
io microsphere util ClassPathUtils
Type: Class | Module: microsphere-java-core | Package: io.microsphere.util | Since: 1.0.0
Source:
microsphere-java-core/src/main/java/io/microsphere/util/ClassPathUtils.java
ClassPathUtils is an abstract utility class that provides methods for retrieving various class path-related information.
- Retrieving bootstrap class paths
- Retrieving application class paths
- Locating the runtime URL of a class by name or type
`// Get all application class paths
Set classPaths = ClassPathUtils.getClassPaths();
for (String path : classPaths) {
System.out.println("ClassPath: " + path);
`
// Get the location of a specific class
URL location = ClassPathUtils.getRuntimeClassLocation(io.microsphere.util.ClassPathUtils.class);
if (location != null) {
System.out.println("Class Location: " + location);
}
}
public abstract class ClassPathUtils implements UtilsAuthor: Mercy
-
Introduced in:
1.0.0 -
Current Project Version:
0.3.20-SNAPSHOT
This component is tested and compatible with the following Java versions:
| Java Version | Status |
|---|---|
| Java 8 | ✅ Compatible |
| Java 11 | ✅ Compatible |
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |
// Get all application class paths
Set<String> classPaths = ClassPathUtils.getClassPaths();
for (String path : classPaths) {
System.out.println("ClassPath: " + path);
}
// Get the location of a specific class
URL location = ClassPathUtils.getRuntimeClassLocation(io.microsphere.util.ClassPathUtils.class);
if (location != null) {
System.out.println("Class Location: " + location);
}Set<String> paths = ClassPathUtils.resolveClassPaths(true, () -> "/lib/a.jar:/lib/b.jar");
// paths contains ["/lib/a.jar", "/lib/b.jar"]
Set<String> empty = ClassPathUtils.resolveClassPaths(false, () -> "");
// empty set returned when not supportedSet<String> bootClassPaths = ClassPathUtils.getBootstrapClassPaths();
for (String path : bootClassPaths) {
System.out.println("Bootstrap ClassPath: " + path);
}Set<String> classPaths = ClassPathUtils.getClassPaths();
for (String path : classPaths) {
System.out.println("ClassPath: " + path);
}String className = "io.microsphere.util.ClassPathUtils";
URL classLocation = ClassPathUtils.getRuntimeClassLocation(className);
if (classLocation != null) {
System.out.println("Class Location: " + classLocation);
} else {
System.out.println("Class not found or not loadable.");
}Class<?> type = io.microsphere.util.ClassPathUtils.class;
URL classLocation = ClassPathUtils.getRuntimeClassLocation(type);
if (classLocation != null) {
System.out.println("Class Location: " + classLocation);
} else {
System.out.println("Class location could not be determined.");
}Add the following dependency to your pom.xml:
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-java-core</artifactId>
<version>${microsphere-java.version}</version>
</dependency>Tip: Use the BOM (
microsphere-java-dependencies) for consistent version management. See the Getting Started guide.
import io.microsphere.util.ClassPathUtils;| Method | Description |
|---|---|
getBootstrapClassPaths |
Resolves class paths from the given supplier if class path is supported. |
getClassPaths |
Returns the set of application class paths. |
getRuntimeClassLocation |
Get Class Location URL from specified class name at runtime. |
getRuntimeClassLocation |
Get Class Location URL from specified Class at runtime. |
public static Set<String> getBootstrapClassPaths()Resolves class paths from the given supplier if class path is supported.
`Set paths = ClassPathUtils.resolveClassPaths(true, () -> "/lib/a.jar:/lib/b.jar"); // paths contains ["/lib/a.jar", "/lib/b.jar"] Set empty = ClassPathUtils.resolveClassPaths(false, () -> ""); // empty set returned when not supported `
public static Set<String> getClassPaths()Returns the set of application class paths.
This method provides access to the class paths used by the Java runtime for loading application classes.
`Set classPaths = ClassPathUtils.getClassPaths();
for (String path : classPaths) {
System.out.println("ClassPath: " + path);
`
}
public static URL getRuntimeClassLocation(@Nullable String className)Get Class Location URL from specified class name at runtime.
If the class associated with the provided className is loaded by the default class loader
(see ClassLoaderUtils#getDefaultClassLoader()), this method returns the location URL of that class.
Otherwise, it returns null.
`String className = "io.microsphere.util.ClassPathUtils";
URL classLocation = ClassPathUtils.getRuntimeClassLocation(className);
if (classLocation != null) {
System.out.println("Class Location: " + classLocation);
` else {
System.out.println("Class not found or not loadable.");
}
}
public static URL getRuntimeClassLocation(@Nonnull Class<?> type)Get Class Location URL from specified Class at runtime.
This method determines the location (URL) from which the provided class was loaded. If the class is a
primitive type, array type, or synthetic type, or if a security manager prevents access to the protection domain,
this method returns null.
`Class type = io.microsphere.util.ClassPathUtils.class;
URL classLocation = ClassPathUtils.getRuntimeClassLocation(type);
if (classLocation != null) {
System.out.println("Class Location: " + classLocation);
` else {
System.out.println("Class location could not be determined.");
}
}
ClassPathUtils
This documentation was auto-generated from the source code of microsphere-java.
annotation-processor
- ConfigurationPropertyAnnotationProcessor
- ConfigurationPropertyJSONElementVisitor
- FilerProcessor
- ResourceProcessor
annotation-test
java-annotations
java-core
- ACLLoggerFactory
- AbstractArtifactResourceResolver
- AbstractConverter
- AbstractDeque
- AbstractEventDispatcher
- AbstractLogger
- AbstractSerializer
- AbstractURLClassPathHandle
- AccessibleObjectUtils
- AdditionalMetadataResourceConfigurationPropertyLoader
- AnnotationUtils
- ArchiveFileArtifactResourceResolver
- ArrayEnumeration
- ArrayStack
- ArrayUtils
- Artifact
- ArtifactDetector
- ArtifactResourceResolver
- Assert
- BannedArtifactClassLoadingExecutor
- BaseUtils
- BeanMetadata
- BeanProperty
- BeanUtils
- BooleanSerializer
- ByteArrayToObjectConverter
- ByteSerializer
- CharSequenceComparator
- CharSequenceUtils
- CharacterSerializer
- CharsetUtils
- ClassDataRepository
- ClassDefinition
- ClassFileJarEntryFilter
- ClassFilter
- ClassLoaderUtils
- ClassPathResourceConfigurationPropertyLoader
- ClassPathUtils
- ClassUtils
- ClassicProcessIdResolver
- ClassicURLClassPathHandle
- CollectionUtils
- Compatible
- CompositeSubProtocolURLConnectionFactory
- CompositeURLStreamHandlerFactory
- ConditionalEventListener
- ConfigurationProperty
- ConfigurationPropertyGenerator
- ConfigurationPropertyLoader
- ConfigurationPropertyReader
- Configurer
- ConsoleURLConnection
- ConstantPoolUtils
- Constants
- ConstructorDefinition
- ConstructorUtils
- Converter
- Converters
- CustomizedThreadFactory
- DefaultConfigurationPropertyGenerator
- DefaultConfigurationPropertyReader
- DefaultDeserializer
- DefaultEntry
- DefaultSerializer
- DelegatingBlockingQueue
- DelegatingDeque
- DelegatingIterator
- DelegatingQueue
- DelegatingScheduledExecutorService
- DelegatingURLConnection
- DelegatingURLStreamHandlerFactory
- DelegatingWrapper
- Deprecation
- Deserializer
- Deserializers
- DirectEventDispatcher
- DirectoryFileFilter
- DoubleSerializer
- EmptyDeque
- EmptyIterable
- EmptyIterator
- EnumSerializer
- EnumerationIteratorAdapter
- EnumerationUtils
- Event
- EventDispatcher
- EventListener
- ExceptionUtils
- ExecutableDefinition
- ExecutableUtils
- ExecutorUtils
- ExtendableProtocolURLStreamHandler
- FastByteArrayInputStream
- FastByteArrayOutputStream
- FieldDefinition
- FieldUtils
- FileChangedEvent
- FileChangedListener
- FileConstants
- FileExtensionFilter
- FileUtils
- FileWatchService
- Files
- Filter
- FilterOperator
- FilterUtils
- FloatSerializer
- FormatUtils
- Functional
- GenericEvent
- GenericEventListener
- Handler
- Handler
- HierarchicalClassComparator
- IOFileFilter
- IOUtils
- ImmutableEntry
- IntegerSerializer
- IterableAdapter
- IterableUtils
- Iterators
- JDKLoggerFactory
- JSON
- JSONArray
- JSONException
- JSONObject
- JSONStringer
- JSONTokener
- JSONUtils
- JarEntryFilter
- JarUtils
- JavaType
- JmxUtils
- LambdaUtils
- ListUtils
- Listenable
- Lists
- Logger
- LoggerFactory
- LoggerUtils
- LoggingFileChangedListener
- LongSerializer
- MBeanAttribute
- MBeanAttributeInfoBuilder
- MBeanConstructorInfoBuilder
- MBeanDescribableBuilder
- MBeanExecutableInfoBuilder
- MBeanFeatureInfoBuilder
- MBeanInfoBuilder
- MBeanNotificationInfoBuilder
- MBeanOperationInfoBuilder
- MBeanParameterInfoBuilder
- ManagementUtils
- ManifestArtifactResourceResolver
- MapToPropertiesConverter
- MapUtils
- Maps
- MavenArtifact
- MavenArtifactResourceResolver
- MemberDefinition
- MemberUtils
- MetadataResourceConfigurationPropertyLoader
- MethodDefinition
- MethodHandleUtils
- MethodHandlesLookupUtils
- MethodUtils
- ModernProcessIdResolver
- ModernURLClassPathHandle
- Modifier
- MultiValueConverter
- MultipleType
- MutableInteger
- MutableURLStreamHandlerFactory
- NameFileFilter
- NoOpLogger
- NoOpLoggerFactory
- NoOpURLClassPathHandle
- NumberToByteConverter
- NumberToCharacterConverter
- NumberToDoubleConverter
- NumberToFloatConverter
- NumberToIntegerConverter
- NumberToLongConverter
- NumberToShortConverter
- NumberUtils
- ObjectToBooleanConverter
- ObjectToByteArrayConverter
- ObjectToByteConverter
- ObjectToCharacterConverter
- ObjectToDoubleConverter
- ObjectToFloatConverter
- ObjectToIntegerConverter
- ObjectToLongConverter
- ObjectToOptionalConverter
- ObjectToShortConverter
- ObjectToStringConverter
- ObjectUtils
- PackageNameClassFilter
- PackageNameClassNameFilter
- ParallelEventDispatcher
- ParameterizedTypeImpl
- PathConstants
- Predicates
- Prioritized
- PriorityComparator
- ProcessExecutor
- ProcessIdResolver
- ProcessManager
- PropertiesToStringConverter
- PropertiesUtils
- PropertyConstants
- PropertyResourceBundleControl
- PropertyResourceBundleUtils
- ProtocolConstants
- ProxyUtils
- QueueUtils
- ReadOnlyIterator
- ReflectionUtils
- ReflectiveConfigurationPropertyGenerator
- ReflectiveDefinition
- ResourceConstants
- ReversedDeque
- Scanner
- SecurityUtils
- SeparatorConstants
- Serializer
- Serializers
- ServiceLoaderURLStreamHandlerFactory
- ServiceLoaderUtils
- ServiceLoadingURLClassPathHandle
- SetUtils
- Sets
- Sfl4jLoggerFactory
- ShortSerializer
- ShutdownHookCallbacksThread
- ShutdownHookUtils
- SimpleClassScanner
- SimpleFileScanner
- SimpleJarEntryScanner
- SingletonDeque
- SingletonEnumeration
- SingletonIterator
- SizeUtils
- StackTraceUtils
- StandardFileWatchService
- StandardURLStreamHandlerFactory
- StopWatch
- StreamArtifactResourceResolver
- Streams
- StringBuilderWriter
- StringConverter
- StringDeserializer
- StringSerializer
- StringToArrayConverter
- StringToBlockingDequeConverter
- StringToBlockingQueueConverter
- StringToBooleanConverter
- StringToByteConverter
- StringToCharArrayConverter
- StringToCharacterConverter
- StringToClassConverter
- StringToCollectionConverter
- StringToDequeConverter
- StringToDoubleConverter
- StringToDurationConverter
- StringToFloatConverter
- StringToInputStreamConverter
- StringToIntegerConverter
- StringToIterableConverter
- StringToListConverter
- StringToLongConverter
- StringToMultiValueConverter
- StringToNavigableSetConverter
- StringToQueueConverter
- StringToSetConverter
- StringToShortConverter
- StringToSortedSetConverter
- StringToStringConverter
- StringToTransferQueueConverter
- StringUtils
- SubProtocolURLConnectionFactory
- SymbolConstants
- SystemUtils
- ThrowableAction
- ThrowableBiConsumer
- ThrowableBiFunction
- ThrowableConsumer
- ThrowableFunction
- ThrowableSupplier
- ThrowableUtils
- TrueClassFilter
- TrueFileFilter
- TypeArgument
- TypeFinder
- TypeUtils
- URLClassPathHandle
- URLUtils
- UnmodifiableDeque
- UnmodifiableIterator
- UnmodifiableQueue
- UnsafeUtils
- Utils
- ValueHolder
- Version
- VersionUtils
- VirtualMachineProcessIdResolver
- Wrapper
- WrapperProcessor
java-test
- Ancestor
- ArrayTypeModel
- CollectionTypeModel
- Color
- ConfigurationPropertyModel
- DefaultTestService
- GenericTestService
- MapTypeModel
- Model
- Parent
- PrimitiveTypeModel
- SimpleTypeModel
- StringArrayList
- TestAnnotation
- TestService
- TestServiceImpl
jdk-tools
lang-model