views:

72

answers:

1

I have created a simple web-service using Java. i want to load jars related to web-service during runtime. I have done this task for normal Java application. there what I did was

            JarFile jar = new JarFile(f.getPath());

final Manifest manifest = jar.getManifest();
final Attributes mattr = manifest.getMainAttributes();

// Read the manifset in jar files and get the Name attribute
// whare it specified the class that need to load
//for (Object a : mattr.keySet()) {
for (Iterator iter = mattr.keySet().iterator(); iter.hasNext();) {
 Object obj = (Object)iter.next();
 if ("ServiceName".equals(obj.toString()))
  className = mattr.getValue((Name) obj);
 //System.out.println(className);
}

/*
 * Create the jar class loader and use the first argument passed
 * in from the command line as the jar file to use.
 */
JarClassLoader jarLoader = new JarClassLoader(f.getPath());

/* Load the class from the jar file and resolve it. */
Class c = jarLoader.loadClass(className, true);

My problem is

  1. can I put jars that need to be loaded during run time in to separate folder rather than putting in to WEBINF folder.

  2. do i have to put jars both in axis and web-application.

thanks in advance for any contribution for this question.

+1  A: 

Where to put your jar's depends on your application server, for tomcat i.g. ${catalina.home}/common/lib would be a place which is already added to the classpath and is visible to your application.

stacker