2

I'm trying to force my application to execute shutdown hooks when clicking the "red square terminate" button in Eclipse. I realize this question was addressed here and here.

I've implemented the following code based on this response and this comment on Eclipse.org forums:

    import java.rmi.RemoteException;

    import org.eclipse.debug.core.DebugException;
    import org.eclipse.debug.core.ILaunch;
    import org.eclipse.debug.core.model.IProcess;
    import org.eclipse.debug.core.model.IStreamsProxy;

    public class JavaProcessDecorator implements IProcess {


    private IProcess p;



    public JavaProcessDecorator(IProcess p) {
        this.p = p;
    }

    private boolean sigkill = false;

    @SuppressWarnings("rawtypes")

    @Override public Object  getAdapter(Class arg)               
    {
        return p.getAdapter(arg);
    }



    @Override public ILaunch getLaunch()                          
    {

        return p.getLaunch(); 

    }


    @Override public IStreamsProxy getStreamsProxy()                    
    {   

        return p.getStreamsProxy(); 

    }


    @Override public void setAttribute(String s1, String s2)   
    {        

        p.setAttribute(s1, s2);     
    }

    @Override public void terminate() throws DebugException    

    {
        if (!sigkill) {

            try {
                IDebugIService cs = DirmiServer.INSTANCE.getRemote("main", IDebugIService.class);
                if(cs != null) cs.modelEvent(new TerminateRequest());
            } catch (RemoteException e) { }
            this.sigkill = true;
        } else p.terminate();

    }



    @Override
    public boolean canTerminate() {
        // TODO Auto-generated method stub
        return false;
    }



    @Override
    public boolean isTerminated() {

        return p.isTerminated();
    }



    @Override
    public String getLabel() {

        return p.getLabel();
    }



    @Override
    public String getAttribute(String key) {

        return p.getAttribute(key);
    }



    @Override
    public int getExitValue() throws DebugException {

        return p.getExitValue();


    }

   }

I've downloaded both DirmiServer and Cojen jars however Eclipse complains in the following two lines:

 IDebugIService cs = DirmiServer.INSTANCE.getRemote("main", IDebugIService.class);
 if(cs != null) cs.modelEvent(new TerminateRequest());

That 'IDebugIService ', 'DirmiServer', 'IDebugIService' and 'TerminateRequest' cannot be resolved to a type?

What am I doing wrong?

Thanks

Alan Cook
  • 342
  • 3
  • 14
  • Well have you added the jars to your plug-in and included them in the `Bundle-ClassPath`? – greg-449 Dec 23 '19 at 07:45
  • @greg-449 What do you mean added jars to plugin and added to `Bundle-ClassPath`? I imported the following jars: `import java.rmi.RemoteException;` `import org.cojen.*;` `import org.cojen.dirmi.*;` – Alan Cook Dec 24 '19 at 02:23
  • I assume you are writing an Eclipse plug-in (the code you show will only work in a plug-in). Jars you want to use in a plug-in must be part of the plug-in, and must be in the plug-in Bundle-Classpath in the plug-in MANIFEST.MF. Alternatively they can be in a different plug-in and referenced by Require-Bundle or Import-Package in the MANIFEST.MF. What you cannot do is just reference some external jar. See for example [this answer](https://stackoverflow.com/a/44393260/2670892) – greg-449 Dec 24 '19 at 07:59

0 Answers0