Пример #1
1
 private static ClassLoader toolsClassLoader() {
   File javaHome = new File(System.getProperty("java.home"));
   File classesDir = new File(javaHome, "classes");
   File libDir = new File(javaHome.getParentFile(), "lib");
   File toolsJar = new File(libDir, "tools.jar");
   try {
     return new URLClassLoader(new URL[] {classesDir.toURL(), toolsJar.toURL()});
   } catch (MalformedURLException e) {
     throw new AssertionError(e);
   }
 }
Пример #2
0
 /**
  * Load image from resource path (using getResource). Note that GIFs are loaded as _translucent_
  * indexed images. Images are cached: loading an image with the same name twice will get the
  * cached image the second time. If you want to remove an image from the cache, use purgeImage.
  * Throws JGError when there was an error.
  */
 @SuppressWarnings({"deprecation", "unchecked"})
 public JGImage loadImage(String imgfile) {
   Image img = (Image) loadedimages.get(imgfile);
   if (img == null) {
     URL imgurl = getClass().getResource(imgfile);
     if (imgurl == null) {
       try {
         File imgf = new File(imgfile);
         if (imgf.canRead()) {
           imgurl = imgf.toURL();
         } else {
           imgurl = new URL(imgfile);
           // throw new JGameError(
           //	"File "+imgfile+" not found.",true);
         }
       } catch (MalformedURLException e) {
         // e.printStackTrace();
         throw new JGameError("File not found or malformed path or URL '" + imgfile + "'.", true);
       }
     }
     img = output_comp.getToolkit().createImage(imgurl);
     loadedimages.put(imgfile, img);
   }
   try {
     ensureLoaded(img);
   } catch (Exception e) {
     // e.printStackTrace();
     throw new JGameError("Error loading image " + imgfile);
   }
   return new JREImage(img);
 }
 /*
  * Save the given configuration to disk.
  */
 public void save(String message, Configuration configuration) {
   File configLocation =
       new File(output, getRootFolder() + "configuration/org.eclipse.update/platform.xml");
   File installLocation = new File(output, getRootFolder());
   try {
     configuration.save(configLocation, installLocation.toURL());
   } catch (ProvisionException e) {
     fail(message, e);
   } catch (MalformedURLException e) {
     fail(message, e);
   }
 }
 public Configuration loadConfiguration(File configLocation, File installLocation) {
   try {
     return Configuration.load(configLocation, installLocation.toURL());
   } catch (ProvisionException e) {
     fail("Error while reading configuration from " + configLocation);
   } catch (MalformedURLException e) {
     fail("Unable to convert install location to URL " + installLocation);
   }
   assertTrue("Unable to read configuration from " + configLocation, false);
   // avoid compiler error
   return null;
 }
Пример #5
0
 public URL getResource(String path) {
   try {
     File f = getFile(path);
     if (!f.exists()) return null;
     return f.toURL();
   } catch (FileNotFoundException fnf) {
     // the spec says to return null if we can't find it
     // even though this is weird...
     return null;
   } catch (IOException ioe) {
     throw new RuntimeException("error opening [" + path + "]", ioe);
   }
 }
Пример #6
0
  public static ClassLoader addFileToClassPath(ClassLoader root, ClassLoader classLoader, File f) {
    if (f.exists() && (!f.isDirectory()) && f.getName().endsWith(".jar")) {

      try {

        classLoader = extendClassLoader(root, classLoader, f.toURL());

      } catch (Exception e) {

        // don't use Debug/lglogger here as we can be called before AZ has been initialised

        e.printStackTrace();
      }
    }

    return (classLoader);
  }