0

数日前から問題に直面しており、解決策が得られません。以下は私のアプリの構造です:

同じレベルの equinox-server-side-app.war (warproduct を使用してビルド) の MyearDeployedOnJboss7.ear 内に ejbapp.jar があり、プラグインにある iModernizeWebClient_1.0.0.jar にある MyJarToLaoadForEjbapp.jar からクラスをロードしたいequinox-server-side-app.war のフォルダー (アプリ構造の画像を表示したいのですが、フォーラムのルールでは 10 点が必要なため、画像を送信できません)

私の質問は、equinox-server-side-app.war にある MyWebClient_1.0.0.jar のプラグイン フォルダ内の「MyJarToLaoadForEjbapp.jar」から ejbapp.jar ロード クラスを許可する方法です。

サーブレットブリッジクラスローダーを使用していると思いますが、使用方法がわかりません。

私のlaunch.iniで私は:

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

1 に答える 1

0

OSGI 仕様の Servlet HttpServiceTracker を使用して問題を解決しました。それを行う方法: HttpServiceTracker liket を書きます:

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

メソッド start のプラグイン アクティベーター クラスで:

@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 メソッドでサーブレットを登録解除するには:

public void stop(BundleContext context) throws Exception {
    Activator.plugin = null;
    serviceTracker.close();
    serviceTracker = null;
    LOGGER.info("servlet unregistered from context !!");
    super.stop(context);
}

それで全部です。サーブレットはEclipseバンドルの外部からアクセスでき、バンドル内のメソッドを呼び出すことができます.

于 2013-06-10T14:26:51.167 に答える