From 0dd186ac6277292cd8af7555952a67abeda9ec92 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:19:33 +0000 Subject: Don't rely on being executed from app dir git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@257 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'pdf-over-gui/src/main') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java index f966bb71..f93c7b5c 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java +++ b/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