java - Web 服务可以在运行时加载 jar 吗

标签 java web-services

我使用 Java 创建了一个简单的 Web 服务。我想在运行时加载与网络服务相关的jar。我已经为普通 Java 应用程序完成了这项任务。我所做的是

            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);

我的问题是

  1. 我可以将运行时需要加载的 jar 放入单独的文件夹中,而不是放入 WEBINF 文件夹中吗?

  2. 我是否必须将 jar 放在 axis 和 Web 应用程序中。

提前感谢您对此问题的任何贡献。

最佳答案

放置 jar 的位置取决于您的应用程序服务器,对于 tomcat i.g. ${catalina.home}/common/lib 将是已添加到类路径中并且对您的应用程序可见的位置。

关于java - Web 服务可以在运行时加载 jar 吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2650983/

相关文章:

wcf - 如何为各种部署更改我的 WCF 的 FederationMetadata.xml 文件?

c# - 尝试连接到 .sdf 数据库时出现异常

java - 如何在 Future.cancel 之后取消生成的 Callable?

java - Struts 测试 JUnit4

java - 在每个 jvm 运行中添加 jar 文件似乎不起作用

java - CXF 服务器端记录到表

java - Tomcat 8 如何设置jarsToSkip

使用 ResourceBundle(locale.properties) 的 Java 本地化文本 Web 服务

java - String#matches 中的\A\z 是多余的吗?

java - 将对象添加到具有两种类型的通用列表