我在恢复项目中的文件时遇到问题,在本地一切正常,没有任何错误,对于使用Jenkins
进行构建时的缺点,我出错了,因为它无法识别文件的路径,我知道c
是在e构建jenkins
期间生成jar
,并且文件的路径发生变化,文件中的调用代码(该路径在属性中定义文件为'src\\main\\webapp\\app'
):
Map<String, List<List<Element>>> htmlFileTagWithoutId = new HashMap<>();
Stream<Path> paths = null;
try (FileReader fileReader = new FileReader(new ClassPathResource(PROPERTY_FILE_NAME).getFile())) {
Properties properties = new Properties();
properties.load(fileReader);
String filePath = properties.getProperty(PROPERTY_KEY);
paths = Files.walk(Paths.get(filePath));
paths.filter(Files::isRegularFile).forEach(file -> {
String fileName = file.getFileName().toString();
String excludedFiles = properties.getProperty(EXCLUDED_FILES);
if (fileName.contains(ENDS_OF_FILES_WITH) && !excludedFiles.contains(fileName)) {
try {
Document document = Jsoup.parse(file.toFile(), CHARSET_NAME);
List<List<Element>> finalReturn = getListOfElementsWithDuplicateId(document);
htmlFileTagWithoutId.put(file.getFileName().toString(), finalReturn);
} catch (Exception e) {
log.error("Error : Can't parse a file {} by Jsoup with exception message : {}", file.getFileName(), e.getMessage());
}
}
});
paths.close();
return htmlFileTagWithoutId;
} catch (IOException e) {
log.debug("Error : Can't create FileReader from properties file path");
throw (e);
}finally {
if(null != paths)
paths.close();
}
我在jenkins
上遇到的错误是:
extractElementWithOutIdtest(com.manpower.direct.recrutement.middleoffice.service.IdEventServiceTest) Time elapsed: 0 sec <<< ERROR!
java.nio.file.NoSuchFileException: src\main\webapp\app
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
at sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:144)
at sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:99)
at java.nio.file.Files.readAttributes(Files.java:1737)
at java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:219)
at java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:276)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:322)
at java.nio.file.FileTreeIterator.<init>(FileTreeIterator.java:72)
at java.nio.file.Files.walk(Files.java:3574)
at java.nio.file.Files.walk(Files.java:3625)
at com.manpower.direct.recrutement.middleoffice.service.IdEventService.extractElementWithOutId(IdEventService.java:50)
at com.manpower.direct.recrutement.middleoffice.service.IdEventServiceTest.extractElementWithOutIdtest(IdEventServiceTest.java:54)
请任何帮助。 非常感谢