Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Servlets 如何在JBoss7的equinox服务器端应用程序中从jar加载类_Servlets_Jboss_Classloader_Equinox_Bridge - Fatal编程技术网

Servlets 如何在JBoss7的equinox服务器端应用程序中从jar加载类

Servlets 如何在JBoss7的equinox服务器端应用程序中从jar加载类,servlets,jboss,classloader,equinox,bridge,Servlets,Jboss,Classloader,Equinox,Bridge,几天来我一直面临一个问题,我无法找到解决办法。以下是我的应用程序结构: 我将ejbap.jar部署在与equinox-server-side-app.war(使用warproduct构建)相同级别的MyearDeployedOnJboss7.ear中,我想从iModernizeWebClient_1.0.0.jar中加载类,它位于equinox-server-side-app.war的plugins文件夹中(我想显示应用程序结构的图像,但我无法发送图像,因为论坛规则需要10分才能做到这一点) 我

几天来我一直面临一个问题,我无法找到解决办法。以下是我的应用程序结构:

我将ejbap.jar部署在与equinox-server-side-app.war(使用warproduct构建)相同级别的MyearDeployedOnJboss7.ear中,我想从iModernizeWebClient_1.0.0.jar中加载类,它位于equinox-server-side-app.war的plugins文件夹中(我想显示应用程序结构的图像,但我无法发送图像,因为论坛规则需要10分才能做到这一点)

我的问题是如何允许EJBAP.jar从equinox-server-side-app.war中MyWebClient_1.0.0.jar的插件文件夹中的“MyJarToLaoadForEjbapp.jar”加载类

我想使用servletbridge类加载器,但不知道如何使用它

在我的launch.ini中,我:

osgi.*=@null org.osgi.*=@null eclipse.*=@null osgi.parentClassloader=app osgi.contextClassLoaderParent=app

我使用OSGI规范中的Servlet HttpServiceTracker解决了我的问题。方法:编写HttpServiceTracker,如:

public class HttpServiceTracker extends ServiceTracker {

private static final Logger logger = Logger
        .getLogger(HttpServiceTracker.class.getName());


public HttpServiceTracker(BundleContext context) {
    super(context, HttpService.class.getName(), null);
}

public Object addingService(ServiceReference reference) {
    HttpService httpService = (HttpService) context.getService(reference);
    logger.info("default context path : "
            + org.eclipse.rap.ui.internal.servlet.HttpServiceTracker.ID_HTTP_CONTEXT);
    try {
        logger.info("will register servlet ");
        httpService.registerServlet("/programLauncherServlet",
                new ProgramLauncherServlet(), null, null);
        logger.info("servlet has been registred with http context ");
        // httpService.registerResources( "/", "/html", null );
    } catch (Exception e) {
        //e.printStackTrace();
        logger.info("The alias '/programLauncherServlet' is already in use");
    }

    return httpService;
}

public void removedService(ServiceReference reference, Object service) {
    logger.info("will unregister servlet ");
    HttpService httpService = (HttpService) service;
    httpService.unregister("/programLauncher");
    super.removedService(reference, service);
    logger.info("servlet has been unregistred");
}
在方法开始时的插件激活器类中:

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    Activator.plugin = this;

    BundleContext osgiContext = BundleReference.class
            .cast(AnyClassOfYourProject.class.getClassLoader()).getBundle()
            .getBundleContext();
    serviceTracker = new HttpServiceTracker(osgiContext);
    serviceTracker.open();
    LOGGER.info("servlet published !!");
    LOGGER.info("Bundle started.");
}
对于在stop方法中注销servlet:

public void stop(BundleContext context) throws Exception {
    Activator.plugin = null;
    serviceTracker.close();
    serviceTracker = null;
    LOGGER.info("servlet unregistered from context !!");
    super.stop(context);
}
仅此而已,您的servlet可以在eclipse包之外访问,并且您可以在包内调用方法