My code accepts a zip file as input.
I have another program that will load these images as resources and put them into the database *if* I can get the temp directory onto the class path. If I can do this I won't have to write new code. Once my program exits, the temp directory should be removed from the classpath. Is there a standard way of going about this? Or is it just a horrific idea? This works pretty well: You can only add folders or jar files to a class loader. So if you have a single class file, you need to put it into the appropriate folder structure first. Here is a rather ugly hack that adds to the SystemClassLoader at runtime: import java.io.IOException;
public class ClassPathHacker { private static final Class[] parameters = new Class[]{URL.class}; public static void addFile(String s) throws IOException
{
public static void addFile(File f) throws IOException
{
public static void addURL(URL u) throws IOException { URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
try {
}//end method }//end class PS: The reflection is necessary to access the protected method addURL. This could fail if there is a SecurityManager.
Do you have a Java Problem?
Java Books
Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|