下面列出了怎么用org.springframework.boot.system.ApplicationHome的API类实例代码及写法,或者点击链接到github查看源代码。
static InteractiveShell createShell(String engine) {
InteractiveShell shell = new InteractiveShell();
ApplicationHome home = new ApplicationHome(BlockRunnerController.class);
Path targetDir = home.getDir().toPath().resolve("djl");
extractJars(targetDir);
shell.addDependencyDir(targetDir.resolve("basic"));
File[] engineFiles = targetDir.resolve("engines").toFile().listFiles();
if (engineFiles == null) {
throw new IllegalStateException("Cannot find Engine files");
}
for (File file : engineFiles) {
if (file.getName().startsWith(engine)) {
shell.addDependency(file.toPath());
}
}
return shell;
}
private File getLogDir() {
if (StringUtils.hasLength(this.jtaProperties.getLogDir())) {
return new File(this.jtaProperties.getLogDir());
}
File home = new ApplicationHome().getDir();
return new File(home, "transaction-logs");
}
@Test
public void narayanaPropertiesInitializerShouldUseDefaultLogDir() {
this.configuration.narayanaPropertiesInitializer(this.mockNarayanaProperties);
File applicationHomeDir = new ApplicationHome().getDir();
File expectedLogDir = new File(applicationHomeDir, "transaction-logs");
verify(this.mockNarayanaProperties).setLogDir(expectedLogDir.getAbsolutePath());
}
public String getClasspath() {
ApplicationHome h = new ApplicationHome(DbUtil.class);
File jarF = h.getSource();
return jarF.getParentFile().toString();
}
/**
* 获取当前运行的路径
*
* @return jar 或者classPath
*/
public static File getRunPath() {
ApplicationHome home = new ApplicationHome(JpomApplication.getAppClass());
String path = (home.getSource() == null ? "" : home.getSource().getAbsolutePath());
return FileUtil.file(path);
}