Simple “check for update” library in java

送分小仙女□ 提交于 2019-12-04 07:31:44

Eclipse now supports p2, a much more flexible system over the old update manager. It can be used to install new software and check for updates on existing software.

You can include the self-updating portion of p2 with no UI, although the full process that includes the Help>Install New updates is described here http://wiki.eclipse.org/Equinox/p2/Adding_Self-Update_to_an_RCP_Application

All updates in eclipse are easier to manager if you use a feature, but the feature is where you can mark your RCP app plugin to be expanded to a directory instead of as a jar (it'll do it automatically).

Adding self-updating to any app is non-trivial. Do you update all jars at once, or only select ones? Which jars does it make sense to update at the same time? With eclipse based on OSGi, how do you make sure that your update leaves your system in a working state? p2 was built to help manage these usecases. See http://wiki.eclipse.org/P2

Edit:

Simple self-updating can be added using the p2 API without including any of the UI code:

public class SelfUpdateOperation {
    public static void update() {
        BundleContext context = FrameworkUtil.getBundle(
                SelfUpdateOperation.class).getBundleContext();
        ServiceReference<?> reference = context
                .getServiceReference(IProvisioningAgent.SERVICE_NAME);
        if (reference == null)
            return;
        Object obj = context.getService(reference);
        IProvisioningAgent agent = (IProvisioningAgent) obj;
        ProvisioningSession session = new ProvisioningSession(agent);
        UpdateOperation update = new UpdateOperation(session);
        IStatus result = update.resolveModal(new NullProgressMonitor());
        if (result.isOK()) {
            update.getProvisioningJob(new NullProgressMonitor()).schedule();
        } else {
            // can't update for some reason
        }
        context.ungetService(reference);
    }
}

This needs a little work (maybe the product has to include the update site), but that's the basic API.

Andrew Thompson

Use Java Web Start to launch the app. Auto-update is one of the main features of JWS.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!