Skip to content

Provide access to the application class path of the image that is currently built #2600

@christianwimmer

Description

@christianwimmer

From within a Feature running at image build time, it is currently not possible to get the class path or module path of the application using proper API.

We should provide methods like this (exact list and signatures to be discussed):

  • List<Path> getClassOrModulePath(): The value of the -cp or -modulepath options passed to native-image
  • boolean isModulePath(): Whether the list is a class or module path
  • ClassLoader getApplicationClassLoader(): Returns the class loader used for the classpath / modulepath.

The methods can either be in FeatureAccess, or in a separate class as static helper methods. I prefer FeatureAccess because the callers should be at a defined point in a Feature and not, e.g., at a random class initializer.

Why provide class and module path in the same method, and a boolean flag if distinction is necessary? Code that scans the path for, e.g., resources or classes likely works the same for class and module path, making it easier to support both.

Alternatives:

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions