下面的方法应该从某个目录中读取类/文件。在eclipse中调试方法时它工作正常。但是在使用 ant 构建它之后,scannedDir 不再是一个目录。有谁知道如何更改它以使其在部署后仍然有效?提前致谢!
private static List<Class<?>> find(String scannedPackage) {
logger.trace("Scanned package='{}'", scannedPackage);
String scannedPath = scannedPackage.replace(DOT, SLASH);
logger.trace("Scanned path='{}'", scannedPath);
URL scannedUrl = Thread.currentThread().getContextClassLoader().getResource(scannedPath);
logger.trace("Scanned url='{}'", scannedUrl);
if (scannedUrl == null) {
throw new IllegalArgumentException(String.format(BAD_PACKAGE_ERROR, scannedPath, scannedPackage));
}
File scannedDir = new File(scannedUrl.getFile());
logger.trace("scannedDir.isDirecory='{}'", scannedDir.isDirectory());
List<Class<?>> classes = new ArrayList<Class<?>>();
for (File file : scannedDir.listFiles()) {
logger.trace("currentFile='{}'", file.getAbsolutePath());
classes.addAll(find(file, scannedPackage));
}
return classes;
}
如此详细:当我使用 eclipse debug mode 运行它时scannedDir.isDirectory=true
。但是建好之后scannedDir.isDirectory=false
干杯!
编辑:
scannedDir.getAbsolutePath()
返回jar:file:/C:/Users/xxx.xxx/AppData/Local/XBRLGEN/app/xbrl_s2.jar!/eu/europa/eiopa/xbrl/s2c/dict/dom