Hi,
I know a quick and dirty solution:
1) get the file out of the jar
2) write it to a temporary file
3) work with that temporary file in your application
4) when the application exits, don't forget to delete the temporary file!
As I said, it's dirty but it works.
-- Didi
PS: Attached is a code snippet that I use for this purpose:
import java.io.*;
import java.util.jar.*;
public class Helper implements GewiAdminConstants {
private String home;
public Helper() {
home =
getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replaceAll("%20",
" ");
}
public static String getTmpDir() {
String tmp = System.getProperty("java.io.tmpdir");
if (!tmp.endsWith("/"))
tmp += "/";
return tmp;
}
public void getResource(String name) {
try {
JarFile jar = new JarFile(home);
JarEntry entry = jar.getJarEntry(name);
File f = new File(getTmpDir() + entry.getName());
if (!f.exists()) {
InputStream entryStream = jar.getInputStream(entry);
FileOutputStream fos = new FileOutputStream(getTmpDir() +
entry.getName());
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = entryStream.read(buffer)) != -1)
fos.write(buffer, 0, bytesRead);
entryStream.close();
fos.close();
}
}
catch (IOException ex) {
ex.printStackTrace();
System.err.println("Could not get resource '" + name + "'!");
}
}
}
> Hello,
> I wrote a Client application, which accesses the server via a
[quoted text clipped - 29 lines]
>
> regards Volker
Volker Boehm - 28 Feb 2006 17:06 GMT
> I know a quick and dirty solution:
>
[quoted text clipped - 4 lines]
>
> As I said, it's dirty but it works.
Hello Dieter,
yes it's very dirty, but it works ... as long as your application has the
right to create a file - at least a temporary file -. When you distibute
your applications with Webstart you must either sign your JAR and the user
must accept the certificate or the certificate must be authenticated by an
offical CA (like verisign).
In my case the application even starts external applications
(AcrobatReader); so I had to sign the jar anyway.
Here is my implementation of the workaround:
Instead of the single line
System.setProperty("javax.net.ssl.trustStore", "MyClient.truststore");
which doesn't work any more if the truststore file is inside the jar, I put
these lines
File tf = File.createTempFile("myclient",".truststore");
tf.deleteOnExit();
byte buffer[] = new byte[0x1000];
InputStream in =
getClass().getResourceAsStream("MyClient.truststore");
FileOutputStream out = new FileOutputStream(tf);
int cnt;
while ((cnt = in.read(buffer)) != -1)
out.write(buffer,0,cnt);
in.close();
out.close();
System.setProperty("javax.net.ssl.trustStore", tf.getAbsolutePath());
regards Volker
Dieter Schicker - 01 Mar 2006 10:40 GMT
Well, at least it's not totally dirty, because the jar file gets
downloaded and a user could extract the file from the jar archive, too ...
Anyway, I would highly appreciate if anyone had a better solution!
Dieter
>>I know a quick and dirty solution:
>>
[quoted text clipped - 34 lines]
>
> regards Volker