开发者

can a webservice load jars during run time

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 (Ob开发者_Python百科ject 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜