gpt4 book ai didi

java - 从另一个 jar 执行 jar 文件

转载 作者:太空宇宙 更新时间:2023-11-04 11:19:02 26 4
gpt4 key购买 nike

我正在从另一个 jar 文件执行一个 jar 文件。从子 jar 访问资源文件时出现异常:java.io.FileNotFoundException:文件“file:PATH_TO_CHILD_JAR/example-1.0.0-0-SNAPSHOT-jar-with-dependency.jar!resource_file_path/abs.sql.tpl”不存在。

我不明白为什么它需要“!”搜索资源文件时进行标记。

最佳答案

您可以在java程序中执行jar文件。

make sure that you have added Manifest file in the jar which has Main-Class attribute.

我的步骤和输出:

使用以下行创建 list 文件:Main-Class: com.demo.TestJar

创建测试Java程序:

package com.demo;
public class TestJar extends Object {
public static void main(String args[]) {
System.out.println("TestJar");
}
}

打包jar:jar cvfm/home/user/TestJarOne.jar manifest.txt

编写测试程序:

import java.io.BufferedInputStream;
import java.io.IOException;

public class TestJSS extends Object {

static int i = 0;

public static void main(String args[]) throws IOException, InterruptedException {
System.out.println("Calling jar");
Process p = Runtime.getRuntime().exec("java -jar /home/user/TestJarOne.jar arg1 arg2");
BufferedInputStream bis = new BufferedInputStream(p.getInputStream());
synchronized (p) {
p.waitFor();
}
System.out.println(p.exitValue());
int b=0;
while((b=bis.read()) >0){

System.out.print((char)b);
}
System.out.println("");
System.out.println("Called jar");
}

}

关于java - 从另一个 jar 执行 jar 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45137144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com