Search code examples
javaclasspathwildcardexpand

How to expand Java Classpath Wildcards from code?


I'd like to expand Java classpath wildcards (New on Java 6) from code. Is there some code in Java Standard Lib that I could use instead of doing it from scratch?

Example:

public static void main(String args[]) {
        method("~/myApp/build/*:~/myLib/build/lib.jar", "com.myapp.parser.ParseClassFile");
    }

    public static void method(String classpath, String classfile) {
        actionWithClassFile(javautilmethodexpand(classpath), classfile);
    }

Thanks in advance


Solution

  • Is there some code in Java Standard Lib that I could use instead of doing it from scratch?

    No. Classpath wildcard expansion is not performed by a standard library in Java, and the expansion is performed even before any classes are loaded by the JVM. It is not a standard in the first place, and is available only if the JRE implementation supports it. As far as I know, the Oracle/Sun and OpenJDK runtimes allow for classpath wildcard expansion.

    Quite obviously, you'll need to roll your own implementation if you intend to do this in Java. You can look up the implementation in C (for the OpenJDK runtime) in the wildcard.c file located in the jdk/src/share/bin directory of the sources.