1 package net.sf.openrocket.util;
5 import java.net.URISyntaxException;
7 import java.security.CodeSource;
9 import net.sf.openrocket.database.Database;
11 public class JarUtil {
14 * Return the a File object pointing to the JAR file that this class belongs to,
15 * or <code>null</code> if it cannot be found.
17 * @return a File object of the current Java archive, or <code>null</code>
19 public static File getCurrentJarFile() {
20 // Find the jar file this class is contained in
22 CodeSource codeSource = Database.class.getProtectionDomain().getCodeSource();
23 if (codeSource != null)
24 jarUrl = codeSource.getLocation();
30 File file = urlToFile(jarUrl);
38 public static File urlToFile(URL url) {
42 } catch (URISyntaxException e) {
44 uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
45 url.getPort(), url.getPath(), url.getQuery(), url.getRef());
46 } catch (URISyntaxException e1) {
47 throw new IllegalArgumentException("Broken URL: " + url);