Packaging with SWT [message #455362] |
Fri, 13 May 2005 04:16 |
Eclipse User |
|
|
|
Originally posted by: xyzzy.foo.gmail.com
Is there a way to package a program with SWT so that it can be run on a
machine where SWT has not been previously installed and so that the
users do not need to install SWT?
-Matt
|
|
|
|
Re: Packaging with SWT [message #455409 is a reply to message #455370] |
Fri, 13 May 2005 14:06 |
Eclipse User |
|
|
|
Originally posted by: martin.j.nilsson.sverige.nu
> Besides adding the swt jars you have to copy the appropriate dll, so,
> etc(Depending on your target platform) to the machine and make it
> available to your VM via the "-Djava.library.path" property.
Just a side-note; you can easily package the DLL(s) inside your jar and
extract them the first time the application is run. Yes, you will leave a
trace of your application (the dll-file) on your user's hard drive, but
IMHO that is not a big issue. If it is I guess you could remove it when
the program quits (at least if it ended normally and not by a kill -9 or
something), but that means that it would have to be extracted on every
start of the application, not just the first.
regards,
martin
|
|
|
|
|
|
|
Re: Packaging with SWT [message #455462 is a reply to message #455453] |
Mon, 16 May 2005 08:01 |
Eclipse User |
|
|
|
Originally posted by: martin.j.nilsson.sverige.nu
Matt,
This is how I would do it, I'm sure there are multiple ways of improving
this code.
private boolean checkSWTInstallation(String swtDllName) {
File javaHome = new File(System.getProperty("java.home"));
File javaBin = new File(javaHome, "bin");
File swtdllDest = new File(javaBin, swtDllName);
if (!swtdllDest.isFile()) {
try {
InputStream is = getClass().getResourceAsStream("resource/" +
swtDllName);
if (is == null) {
return false;
}
try {
OutputStream os = new FileOutputStream(swtdllDest);
try {
byte[] buf = new byte[4096];
for (;;) {
int actual = is.read(buf);
if (actual <= 0) {
break;
}
os.write(buf, 0, actual);
}
} finally {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException iox) {
iox.printStackTrace();
return false;
}
}
return true;
}
|
|
|
Powered by
FUDForum. Page generated in 0.25673 seconds