2

How can I find the version of an installed NetBeans module ?

My purpose is to make my module display its own specification number to the user without having to change its display code at each release.

4

1 回答 1

3
import org.netbeans.api.autoupdate.UpdateElement;
import org.netbeans.api.autoupdate.UpdateManager;
import org.netbeans.api.autoupdate.UpdateUnit;

public class VersionUtil {

  public static String getVersion(String codename) {
    for (UpdateUnit updateUnit : UpdateManager.getDefault().getUpdateUnits()) {
      UpdateElement updateElement = updateUnit.getInstalled();
      if (updateElement != null)
        if (codename.equals(updateElement.getCodeName()))
          return updateElement.getSpecificationVersion();
    }

    return "unknown";
  }
}
于 2010-07-13T18:12:44.830 回答