I have jar file Test2 contained in jar file Test1, and I execute Test1. When I try to execute Test2 using java.awt.Desktop
I get the java.lang.IllegalArgumentException: URI is not hierarchical
exception and message. I can do it successfully when I have Test2 separate from Test1 (i.e. Test2 in a different folder) and access it like below:
Desktop.getDesktop().open(new File("path-to-file\\Test2.jar"));
And I can do the following from my IDE without any problems:
Desktop.getDesktop().open(new File(Test.class.getResource("Test2.jar").toURI()));
I have problems running Test2 when I run the jar file Test1 using the above line of code.
Through research, I learned that you have to do something like InputStream is = Test.class.getClassLoader().getResourceAsStream(...);
. What I couldn't figure out, however, is what, if anything, you have to do with this InputStream
to successfully execute a jar from within a jar, or what this InputStream
does to make the URI hierarchical. So far this is I came up with (I don't know if I even have the first file correct):
InputStream is = Test.class.getClassLoader().getResourceAsStream("Test2.jar");
Desktop.getDesktop().open(new File(Test.class.getResource("Test2.jar").toURI()));
Can anyone shed light on this?