我有一個罐子裏面包含另一個罐子,我的目標是從全局罐子裏運行這個「內部罐子」。運行從另一個罐子的罐子
我有這種方法,其檢索包含在所述罐子
private static String getRealPathFromResourceName(String fileName) throws IOException {
ClassLoader cl = Main.class.getClassLoader();
URL resource = cl.getResource(fileName);
String path = resource.getPath();
return path;
}
然後我運行jar的完整路徑是:
public static boolean exportFullPeriod(CheckConfiguration checkConfig) throws IOException {
final String cmdLine = buildExportCommandLine(checkConfig);
try {
Process process = Runtime.getRuntime().exec(cmdLine);
....
} catch (
...
}
其中建立exportCommandLine構建使用先前的完整的命令行方法,全部輸出爲:
java -jar file:/C:/Users/xxx/target/module-backup-1.0.jar!/export-1.1.jar -dbUrl jdbc:mysql://localhost:3306/test -dbPassword test -dbUser test
我得到的錯誤是以下
Error: Unable to access jarfile file:/C:/Users/xxx/target/module-backup-1.0.jar!/export-1.1.jar
如何引用我的jar中的jar來調用它?
是你嘗試執行依賴的jar tmp的項目嗎?如果是,爲什麼不實際調用jar的main()? –
它不是一個依賴項,我將它作爲資源添加 – Max
好吧。那爲什麼不把它作爲一個庫來添加呢? –