From 99fc9f0eb315d56d2dd80467537c521f3bf44d52 Mon Sep 17 00:00:00 2001 From: Tobias Kellner Date: Fri, 9 Nov 2012 10:55:41 +0100 Subject: Don't rely on being executed from app dir --- .../src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'trunk/pdf-over-gui/src/main/java/at') diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java index f966bb71..f93c7b5c 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java @@ -42,12 +42,12 @@ public class SWTLoader { */ public static void loadSWT() throws InitializationException { try { - log.debug("loading " + getSwtJarName()); URLClassLoader cl = (URLClassLoader)SWTLoader.class.getClassLoader(); Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); addUrlMethod.setAccessible(true); - String swtLibPath = "lib-swt/" + getSwtJarName(); + String swtLibPath = getSwtJarPath() + getSwtJarName(); + log.debug("loading " + swtLibPath); File swtLib = new File(swtLibPath); if (!swtLib.isFile()) throw new SWTLoadFailedException("Library " + swtLibPath + " not found"); @@ -79,6 +79,14 @@ public class SWTLoader { return "swt-" + os + "-" + getArchBits() + ".jar"; } + private static String getSwtJarPath() { + String path = SWTLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + int idx = path.lastIndexOf('/'); + idx = path.lastIndexOf('/', idx - 1); + path = path.substring(0, idx + 1); + return path + "lib-swt/"; + } + private static class SWTLoadFailedException extends Exception { private static final long serialVersionUID = 1L; @@ -86,4 +94,5 @@ public class SWTLoader { super(msg); } } + } -- cgit v1.2.3