Skip to content

Ignore non-existent classpath entries #456

@johnzeringue

Description

@johnzeringue

Running native-image with non-existent classpath entries (i.e. native-image Main -cp /not/a/real/dir) causes an error like

Error: Invalid Path entry /not/a/real/dir
Caused by: java.nio.file.NoSuchFileException: /not/a/real/dir

However, the java binary doesn't care about these types of classpath entries. Something like java Main -cp /real/file.jar:/not/a/real/file.jar:/real/dir:/not/a/real/dir is fine as long as Main doesn't end up missing classes it needs.

I only care because better conformance to java's behavior would ease tooling integration. For example, you can reuse Gradle's JavaExec(!) task to easily integrate GraalVM:

task buildNativeImage(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = "com.example.Main"
    executable = "native-image"
    jvmArgs "--static", "-H:+ReportUnsupportedElementsAtRuntime"
}

This automatically generates complicated classpaths from project and Maven dependencies and works nicely. However, it breaks if you don't have any resources. In that case, it doesn't create the output directory for resources but will still list it in the classpath, breaking native-image.

In general, using native-image should be simpler for many scripts/tools if they're not responsible for making sure all directories on the classpath exist.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions