我尝试从Windows注册表中读取值。当我在Intellij Idea中运行它时,这段代码很有用。
public static String getInstallLocationValue() {
String value = WinRegistry.getString(
WinRegistry.HKEY_LOCAL_MACHINE,
"SOFTWARE\\" + ApplicationConstants.APP_NAME + "\\",
"InstallLocation");
System.out.println("Windows Distribution = " + value);
return value;
}
但是当我从jar文件中运行它时崩溃了:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/deploy/util/WinRegistry at com.doos.utils.RegistryManager.getInstallLocationValue(RegistryManager.java:10) at com.doos.core.Main.main(Main.java:51)
Caused by: java.lang.ClassNotFoundException: com.sun.deploy.util.WinRegistry
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
你有任何想法,如何解决这个问题?