Reputation: 145
I am executing a jar file from another jar file. While accessing resources file from child jar it is giving exception : java.io.FileNotFoundException: File 'file:PATH_TO_CHILD_JAR/example-1.0.0-0-SNAPSHOT-jar-with-dependencies.jar!resource_file_path/abs.sql.tpl' does not exist.
I am not able to figure why it is taking "!" mark while searching for resource files.
Upvotes: 1
Views: 1253
Reputation: 3522
you can execute the jar file with in java program.
make sure that you have added Manifest file in the jar which has Main-Class attribute.
My steps and output:
Created manifest file with the following line: Main-Class: com.demo.TestJar
Created Test Java program:
package com.demo;
public class TestJar extends Object {
public static void main(String args[]) {
System.out.println("TestJar");
}
}
Package the jar : jar cvfm /home/user/TestJarOne.jar manifest.txt
Write test program:
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");
}
}
Upvotes: 1
Reputation: 476
Try this
// Run a java app in a separate system process
Process proc = Runtime.getRuntime().exec("java -jar A.jar");
// Then retreive the process output
InputStream in = proc.getInputStream();
InputStream err = proc.getErrorStream();
Upvotes: 0