【发布时间】:2017-12-12 09:55:16
【问题描述】:
我有一个下面的 CSV 字符串,我想检查给定的文件或目录是否存在。
private static String dir = "/Users/swapnil.kotwal/Swapnil/myproject/build/WEB-INF/classes/test/";
private static String csvConnClasses = dir + "FirstTest*.class,"+ dir+"SecondTest.class,"+dir+"abcd/";
我尝试了下面的代码,但我通过 ant 运行它得到异常 java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
File dir = new File(cls.substring(0, cls.lastIndexOf("/")));
String[] splits = dir.getAbsolutePath().split(dir.getPath());
String basePath = splits[0] + "build/WEB-INF/classes/" + dir.getPath();
dir = new File(basePath);
if (dir.exists() && dir.isDirectory() && dir.list().length > 0) {
final String className = getClassName(new File(cls));
File[] files = dir.listFiles(new FileFilter() {
public boolean accept(File file) {
System.out.println("File Name >>> " + file.getName());
return (file.getName().startsWith(className) && file.getName().endsWith(".class"));
}
});
if (files.length == 0) {
throw new BuildException(cls + " class not found - ");
}
if (classSet.contains(cls)) {
dups.add(cls);
}
classSet.add(cls);
} else
throw new BuildException(cls + " directory not found - ");
}
有人可以建议我使用 PathMatcher/Regex 来检查给定的文件和文件夹是否存在。
【问题讨论】:
-
aspectj/Signature与您的代码有什么关系?为什么代码没有引用csvConnClasses?你为什么发布赏金然后接受你自己的答案? -
CSV string这是在哪里? -
我从一些我刚刚在这里硬编码的复杂机制中获取 CSV。
-
我们使用
Aspectj库将类加载到ant build类路径@RunTime。我使用了匿名内部类new FileFilter,这在ant build jar操作期间给我带来了问题
标签: java regex file ant filepath