How do I modify the CLASSPATH from a running program?

Rob Edmondson

Even with signed code it is impractical to modify the CLASSPATH with Java. There is no Java API (as of jdk1.2) that allows you to write to the registry, or modify environment variables. You can however modify the CLASSPATH using native code.

To modify Windows registry entries use DWORD SHSetValue(HKEY hkey, LPCTSTR pszSubKey, LPCTSTR pszValue, DWORD dwType, LPCVOID pvData, DWORD cbData) defined in Shlwapi.h in the MS Shell Utility APIs (Well documented in the MSDN Library). To modify the CLASSPATH environment variable, use the Win32 function BOOL SetEnvironmentVariable(LPCTSTR lpszName, LPCTSTR lpszValue). The user will have to log out and back in for the changes to take, but many Windows apps respond to the WM_WININICHANGE message by reloading their environment blocks.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.