JTReg uses this code to compute the test class path in method `getJavaTestClassPath()` of class `RegressionParameters` in package `com.sun.javatest.regtest.config`:
// append jtreg.jar to the path
javaTestClassPath.append(new File(installDir, "jtreg.jar"));
Note: if that JAR file is not present, the append call is a silent no-op.
Running jtreg's main entry point in a custom setup, like directly from within an IDE, is not possible, because `jtreg.jar` is not available.
However, all classes that make up jtreg are available in an exploded form, generated by an IDE. Hence, if `jtreg.jar` is not available at the expected location, we should instead add the directory of the current class' code source location. Possibly, using the following snippet:
// append jtreg.jar or exploded directory to the search path
File jtreg = new File(installDir, "jtreg.jar");
if (jtreg.exists()) {
javaTestClassPath.append(jtreg);
} else try {
// use code source location of this class instead
URL location = getClass().getProtectionDomain().getCodeSource().getLocation();
javaTestClassPath.append(new File(location.toURI()));
} catch (Exception e) {
throw new RuntimeException(e);
}
// append jtreg.jar to the path
javaTestClassPath.append(new File(installDir, "jtreg.jar"));
Note: if that JAR file is not present, the append call is a silent no-op.
Running jtreg's main entry point in a custom setup, like directly from within an IDE, is not possible, because `jtreg.jar` is not available.
However, all classes that make up jtreg are available in an exploded form, generated by an IDE. Hence, if `jtreg.jar` is not available at the expected location, we should instead add the directory of the current class' code source location. Possibly, using the following snippet:
// append jtreg.jar or exploded directory to the search path
File jtreg = new File(installDir, "jtreg.jar");
if (jtreg.exists()) {
javaTestClassPath.append(jtreg);
} else try {
// use code source location of this class instead
URL location = getClass().getProtectionDomain().getCodeSource().getLocation();
javaTestClassPath.append(new File(location.toURI()));
} catch (Exception e) {
throw new RuntimeException(e);
}