I've used axis 1.2, maybe the parent classloader i didn't use, maybe the axis version.

El mar, 08 de 11 de 2005 a las 09:53, Deepal Jayasinghe escribió:

Hi all;
 
I do not know I am giving the correct answer , I did the same kind of thing in Axis2 to load jars in lib directories , there I got the create a URL [] getting url from each and every jar in the lib directory , and it worked perfectly with me. Following are the code that I used ;
 
public static ClassLoader getClassLoader(ClassLoader parent , File file) throws DeploymentException {
        URLClassLoader classLoader;
        if (file != null) {
            try {
                ArrayList urls = new ArrayList();
                urls.add(file.toURL());
                //if lib is simple
                File libfiles = new File(file, "lib");
                if (libfiles.exists()) {
                    urls.add(libfiles.toURL());
                    File jarfiles [] = libfiles.listFiles();
                    for (int i = 0; i < jarfiles.length; i++) {
                        File jarfile = jarfiles[i];
                        if (jarfile.getName().endsWith(".jar")) {
                            urls.add(jarfile.toURL());
                        }
                    }
                }
                //if lib is capital
                libfiles = new File(file, "Lib");
                if (libfiles.exists()) {
                    urls.add(libfiles.toURL());
                    File jarfiles [] = libfiles.listFiles();
                    for (int i = 0; i < jarfiles.length; i++) {
                        File jarfile = jarfiles[i];
                        if (jarfile.getName().endsWith(".jar")) {
                            urls.add(jarfile.toURL());
                        }
                    }
                }
                URL urllist [] = new URL[urls.size()];
                for (int i = 0; i < urls.size(); i++) {
                    urllist[i] = (URL) urls.get(i);
                }
                classLoader = new URLClassLoader(urllist, parent);
                return classLoader;
            } catch (MalformedURLException e) {
                throw new DeploymentException(e);
            }
        }
        return null;
    }

Thanks,
 Deepal
................................................................
~Future is Open~

----- Original Message -----
From:
Jorge Martín Cuervo
To: [EMAIL PROTECTED]
Cc: [email protected]
Sent: Monday, November 07, 2005 3:21 PM
Subject: Re: custom classloader

The class Boot begins downloading upgrades from web and then starts the main application class. I use several classloaders, one per operation. The last one is the application main classloader.

I began using a URLClassloader and a recursive jar finder method to add .jar to it. And it didn't work. Then i tryed with ClassLoader.getSystemClassLoader() and works. I don't know the differences but now works.

This is the code that works (bolded code is the first attempt):

package com.defactops.smartcv.swt;


import java.io.File;
import java.io.FileFilter;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/*
* $Id: Boot.java,v 1.4 2005/11/04 18:46:01 jorge Exp $
* $Log: Boot.java,v $
* Revision 1.4  2005/11/04 18:46:01  jorge
* bugfix
*
* Revision 1.3  2005/11/03 09:36:34  jorge
* classloaders distintos en mover y actualizar
*
* Revision 1.2  2005/11/02 22:50:44  jorge
* nuevo arranque
*
* Revision 1.1  2005/11/02 19:28:50  jorge
* test autoupdate
*
* Created on 02-nov-2005 12:35:55
*
*/

/**
* @author Jorge Martin Cuervo <
[EMAIL PROTECTED]>
*
*/
public class Boot {

private static URL[] jarFinder(File path) throws Exception {

List valRet = new ArrayList();

File[] files = path.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.getName().endsWith(".jar") || pathname.isDirectory();
}
});


for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory() ) {
valRet.addAll(Arrays.asList(jarFinder(files[i])));
} else {
valRet.add(files[i].toURL());
}

}
return (URL[])valRet.toArray(new URL[0]);
}





public static void main(String[] args) throws Exception {

Object obj = null;
ClassLoader loader = null;
boolean reboot = false;

do {
loader = new URLClassLoader(jarFinder(new File(".")));
obj = loader.loadClass("com.defactops.smartcv.swt.CheckUpdates").newInstance();
obj.getClass().getMethod("moveDownloadedFiles", null).invoke(obj, null);

obj = null;
loader = null;
System.gc();

loader = new URLClassLoader(jarFinder(new File(".")));
obj = loader.loadClass("com.defactops.smartcv.swt.CheckUpdates").newInstance();
reboot = ((Boolean)obj.getClass().getMethod("checkUpdates", null).
invoke(obj, null)).booleanValue();

obj = null;
loader = null;
System.gc();

} while (reboot);


URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
Class sysclass = URLClassLoader.class;

Method method = sysclass.getDeclaredMethod("addURL",new Class[]{URL.class});
method.setAccessible(true);

URL[] u = jarFinder(new File("."));
for (int i = 0; i < u.length; i++) {
method.invoke(sysloader,new Object[]{ u[i] });
}

/*loader = new URLClassLoader(jarFinder(new File(".")));
obj = loader.loadClass("com.defactops.smartcv.swt.RunApp").newInstance();
obj.getClass().getMethod("startup", null).invoke(obj, null);

obj = null;
loader = null;
System.gc();*/


obj = Class.forName("com.defactops.smartcv.swt.RunApp").newInstance();
obj.getClass().getMethod("startup", null).invoke(obj, null);


}
}

El vie, 04 de 11 de 2005 a las 16:32, Davanum Srinivas escribió:
Are u sure activation.jar is in the directory and is picked up by the
custom class loader?

On 04 Nov 2005 16:31:33 +0100, Jorge Martín Cuervo
<[EMAIL PROTECTED]> wrote:
>            Hi all,
>
>  Before i've used a custom classloader wss4j works good.  After i change it with the one above, i get this error message:
>
>  [...]
>  Exception in thread "main" java.lang.reflect.InvocationTargetException
>  [Loaded java.lang.StackTraceElement from /usr/java/j2sdk1.4.2_05/jre/lib/rt.jar]
>          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>          at java.lang.reflect.Method.invoke(Method.java:324)
>          at Boot.main(Boot.java:91)
>  Caused by: java.lang.NoClassDefFoundError: javax/activation/DataSource
>          at java.lang.Class.forName0(Native Method)
>          at java.lang.Class.forName(Class.java:141)
>          at org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory.class$(JAFDataHandlerSerializerFactory.java:37)
>          at org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory.getSerializerClass(JAFDataHandlerSerializerFactory.java:46)
>          at org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory.<init>(JAFDataHandlerSerializerFactory.java:34)
>          at org.apache.axis.encoding.DefaultTypeMappingImpl.initMappings(DefaultTypeMappingImpl.java:120)
>          at org.apache.axis.encoding.DefaultTypeMappingImpl.<init>(DefaultTypeMappingImpl.java:91)
>          at org.apache.axis.encoding.DefaultTypeMappingImpl.getSingletonDelegate(DefaultTypeMappingImpl.java:85)
>          at org.apache.axis.encoding.TypeMappingRegistryImpl.<init>(TypeMappingRegistryImpl.java:155)
>          at org.apache.axis.encoding.TypeMappingRegistryImpl.<init>(TypeMappingRegistryImpl.java:149)
>          at org.apache.axis.deployment.wsdd.WSDDDeployment.<init>(WSDDDeployment.java:449)
>          at org.apache.axis.deployment.wsdd.WSDDDocument.setDocument(WSDDDocument.java:139)
>          at org.apache.axis.deployment.wsdd.WSDDDocument.<init>(WSDDDocument.java:65)
>          at org.apache.axis.configuration.FileProvider.configureEngine(FileProvider.java:179)
>          at org.apache.axis.AxisEngine.init(AxisEngine.java:172)
>          at org.apache.axis.AxisEngine.<init>(AxisEngine.java:156)
>          at org.apache.axis.client.AxisClient.<init>(AxisClient.java:52)
>          at org.apache.axis.client.Service.getAxisClient(Service.java:103)
>          at org.apache.axis.client.Service.<init>(Service.java:143)
>          at com.defactops.smartcvws.services.SmartCVWS.CandidateWSServiceLocator.<init>(Unknown Source)
>          at com.defactops.smartcv.swt.composites.windows.code.LoadRemoteCodeComposite.do_bAdd_widgetSelected(Unknown Source)
>          at com.defactops.smartcv.swt.composites.windows.CommonRemoteComposite$1.widgetSelected(Unknown Source)
>          at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90)
>          at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
>          at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1021)
>          at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2867)
>          at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2572)
>          at com.defactops.smartcv.swt.RunApp.startup(Unknown Source)
>          ... 5 more
>  [Loaded java.lang.Shutdown from /usr/java/j2sdk1.4.2_05/jre/lib/rt.jar]
>  [...]
>
>
>  I'm not sure if its axis or wss4j problem..
>
>
>
>  public class Boot {
>
>  	private static URL[] jarFinder(File path) throws Exception {
>  		
>  		List valRet = new ArrayList();
>  		
>  		File[] files = path.listFiles(new FileFilter() {
>  			public boolean accept(File pathname) {
>  				return pathname.getName().endsWith(".jar") || pathname.isDirectory();
>  			}
>  		});
>  		
>  		
>  		for (int i = 0; i < files.length; i++) {
>  			if (files[i].isDirectory() ) {
>  				valRet.addAll(Arrays.asList(jarFinder(files[i])));
>  			} else {
>  				valRet.add(files[i].toURL());
>  			}
>  			
>  		}
>  		return (URL[])valRet.toArray(new URL[0]);
>  	}
>  	
>  	public static void main(String[] args) throws Exception {
>  		
>  		Object obj = null;
>  		ClassLoader loader = null;
>  		boolean reboot = false;
>  		
>  		loader = new URLClassLoader(jarFinder(new File(".")), parent);
>  		Thread.currentThread().setContextClassLoader(loader);
>  		obj = loader.loadClass("com.defactops.smartcv.swt.RunApp").newInstance();
>  		obj.getClass().getMethod("startup", null).invoke(obj, null);
>  		
>  		obj = null;
>  		loader = null;
>  		System.gc();
>  		
>  		
>  	}
>  }
>
>
>   --
> ;-)
> ____________________________________
> Jorge Martin Cuervo
> Analista Programador
>
> Outsourcing Emarketplace
> deFacto Powered by Standards
>
> email <[EMAIL PROTECTED]>
> voz +34 985 129 820
> voz +34 660 026 384
> ____________________________________
>



--
Davanum Srinivas : http://wso2.com/blogs/

-- 
;-)
____________________________________
Jorge Martin Cuervo
Analista Programador

Outsourcing Emarketplace
deFacto Powered by Standards

email <[EMAIL PROTECTED]>
voz +34 985 129 820
voz +34 660 026 384
____________________________________
-- 
;-)
____________________________________
Jorge Martin Cuervo
Analista Programador

Outsourcing Emarketplace
deFacto Powered by Standards

email <[EMAIL PROTECTED]>
voz +34 985 129 820
voz +34 660 026 384
____________________________________

Reply via email to