Q:

"URI is not hierarchical" + private key

I just started using Jsch for an SSH connection in my Java program (made for Windows 7). I am running into an issue incorporating a private key into my program. I use the following code: 
URL keyFileURL = Main.class.getResource("auth/public_key_1");
URI keyFileURI = keyFileURL.toURI();
jsch.addIdentity(new File(keyFileURI).getAbsolutePath());

Where "auth" is a folder in the same package. The good news is that everything works fine when running it in Eclipse, however it fails when running it as a jar. The error that is given is: "IllegalArgumentException: URI is not hierarchical".
I know the error has to do with pathnames and using URI as a File, but I don't know how else to reference a resource within the jar file without externally importing it (i.e. from file in same folder as jar) AND still have it compatible with Jsch.
Can someone help me with the code to appropriately reference a resource in the program and still have Jsch accept it as a key.
Thank you in advance for any and all help.
Update:
I tried @bmargulies recommended code:
    String authfile;

     URL resUrl = Resources.getResource(Main.class, "auth/public_key_1");
     File tempFile = File.createTempFile("key", ".key");
     ByteSink sink = Files.asByteSink(tempFile);
     try (OutputStream os = sink.openStream()) {
         Resources.copy(resUrl, os);
         authfile = os.toString();
         jsch.addIdentity(authfile);
     }

But it gives me error: "java.io.FileOutputStream (The system cannot find the file specified)". Is there anything I should fix in the code or any other suggestions?

A:

That's not how you read a resource. You can't get a File for a resource, only a stream. The URL's for resources don't correspond to files.
If jsch can handle a stream, pass it the results of getResourceAsStream.
If jsch can handle an array of bytes, pass it the results of reading the stream into an array of bytes.
If it must have a file, create a temp file.
In the third case, I'd incorporate Guava and write the code like:
URL resUrl = Resources.getResource(Main.class, "auth/public_key1");
File tempFile = File.createTempFile("key", ".key");
ByteSink sink = Files.asByteSink(tempFile);
try (OutputStream os = sink.openStream()) {
    Resources.copy(resUrl, os);
}

and pass the File's path to jsch.

