Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Load jar file during plugin startup using JDK 12 #2

Open
raghuhollap opened this issue Mar 23, 2021 · 0 comments
Open

Unable to Load jar file during plugin startup using JDK 12 #2

raghuhollap opened this issue Mar 23, 2021 · 0 comments

Comments

@raghuhollap
Copy link

I am trying to load a jar file during plugin startup. But unable to load it with JDK 12 or later version.
below is the code snippet :
-------------------------------------CODE---------------------------------------------------
URLClassLoader urlSysLoader = new URLClassLoader(new URL[] {url}, sysLoader);
Method method = sysClass.getDeclaredMethod("addURL", parameters);
/**

The addURL() appends the specified URL to the list of URLs to search for
classes and resources. and since this Method is Protected and we are not inheriting
i'm forced to make it visible.
*/
method.setAccessible(true);
// Invoke addURL method with jar URL to add the classes to URL ClassLoader
method.invoke(urlSysLoader, new Object[] { url });
Field scl = ClassLoader.class.getDeclaredField("scl");
scl.setAccessible(true);
// Replace the static scl (System Class Loader for running instance) with
// newly created URL ClassLoader (system class loader + jar files loaded)
scl.set(null, urlSysLoader);
-----------------------------------------CODE----------------------------------------------
Getting below error :
----------------------------------------ERROR---------------------------------------------------------------------------------
java.lang.NoSuchFieldException: scl
at java.base/java.lang.Class.getDeclaredField(Class.java:2569)
at com.unisys.tde.core.characterset.OS2200CharSetPlugin.loadCharSetLib(OS2200CharSetPlugin.java:160)
at com.unisys.tde.core.characterset.OS2200CharSetPlugin$1.run(OS2200CharSetPlugin.java:66)
----------------------------------------ERROR---------------------------------------------------------------------------------

The above code was working till JDK 11 version.

Please let me know any suggestion or any other alternative approach to achieve the same.

Thanks and Regards,
Raghu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant