dynamic-class-loaders

Reloading jar files contents dynamically

我的未来我决定 提交于 2019-12-02 01:12:20
I have one jar file in my application's class path. At run time, I add new classes to the jar file and sometimes also modify the fields/methods of the existing classes. Currently I am using URLClassLoader to load the classes dynamically. The new classes added dynamically are loaded correctly and I am able to use them at runtime. But it fails to reload the existing classes that are modified at runtime. I read many articles which states we need to explicitly handle reloading because class once loaded will not be reloaded until all the references to the class are destroyed. Also I tried out

Mockito's mock throw ClassNotFoundException in Spark application

六眼飞鱼酱① 提交于 2019-12-01 06:26:27
I found that mock object in Mockito would throw ClassNotFoundException when used in Spark. Here is a minimal example: import org.apache.spark.{SparkConf, SparkContext} import org.mockito.{Matchers, Mockito} import org.scalatest.FlatSpec import org.scalatest.mockito.MockitoSugar trait MyTrait { def myMethod(a: Int): Int } class MyTraitTest extends FlatSpec with MockitoSugar { "Mock" should "work in Spark" in { val m = mock[MyTrait](Mockito.withSettings().serializable()) Mockito.when(m.myMethod(Matchers.any())).thenReturn(1) val conf = new SparkConf().setAppName("testApp").setMaster("local") val

Mockito's mock throw ClassNotFoundException in Spark application

折月煮酒 提交于 2019-12-01 05:29:19
问题 I found that mock object in Mockito would throw ClassNotFoundException when used in Spark. Here is a minimal example: import org.apache.spark.{SparkConf, SparkContext} import org.mockito.{Matchers, Mockito} import org.scalatest.FlatSpec import org.scalatest.mockito.MockitoSugar trait MyTrait { def myMethod(a: Int): Int } class MyTraitTest extends FlatSpec with MockitoSugar { "Mock" should "work in Spark" in { val m = mock[MyTrait](Mockito.withSettings().serializable()) Mockito.when(m.myMethod

How to load unknown class from downloaded jar file during runtime?

佐手、 提交于 2019-11-30 20:22:44
问题 I'm building a client server application. During runtime the client application loads a jar file from the server application and stores it. I run both the client and the server application as jar files. I now want to load the class contained in this downloaded jar file. For example I have an interface A and a class B implementing A. The client application does not know about the class B, its name or even its existence. After the start of the client application the client applications

Dynamic class loading in Python 2.6: RuntimeWarning: Parent module 'plugins' not found while handling absolute import

自闭症网瘾萝莉.ら 提交于 2019-11-30 08:16:35
I am working on a plugin system where plugin modules are loaded like this: def load_plugins(): plugins=glob.glob("plugins/*.py") instances=[] for p in plugins: try: name=p.split("/")[-1] name=name.split(".py")[0] log.debug("Possible plugin: %s", name) f, file, desc=imp.find_module(name, ["plugins"]) plugin=imp.load_module('plugins.'+name, f, file, desc) getattr(plugin, "__init__")(log) instances=instances+plugin.get_instances() except Exception as e: log.info("Failed to load plugin: "+str(p)) log.info("Error: %s " % (e)) log.info(traceback.format_exc(e)) return instances The code works, but

Java Class Loaders [closed]

♀尐吖头ヾ 提交于 2019-11-28 15:55:08
Can anyone point me a good resource or explain me about the concept behind Class Loaders? I found the following resource on class loaders http://www.onjava.com/lpt/a/5586 but still no help. The following questions may look silly but trying to answer them always confuses me. Why do developers write Custom class loaders, why not invoke a Bootstrap class loader to invoke your custom classes? What is the need to define custom class loaders? Why there are so many varieties of class loaders? eg: Bootsrap, Comman, Catalina class loader etc., Thanks in advance. I found the following, valid reasons to

Custom Class Loading in Dalvik with Gradle (Android New Build System)

限于喜欢 提交于 2019-11-28 15:29:13
As per the introduction of Custom Class Loading in Dalvik by Fred Chung on the Android Developers Blog: The Dalvik VM provides facilities for developers to perform custom class loading. Instead of loading Dalvik executable (“dex”) files from the default location, an application can load them from alternative locations such as internal storage or over the network. However, not many developers have the need to do custom class loading. But those who do and follow the instructions on that blog post, might have some problems mimicking the same behavior with Gradle, the new build system for Android

Java Class Loaders [closed]

≯℡__Kan透↙ 提交于 2019-11-27 19:51:26
问题 Can anyone point me a good resource or explain me about the concept behind Class Loaders? I found the following resource on class loaders http://www.onjava.com/lpt/a/5586 but still no help. The following questions may look silly but trying to answer them always confuses me. Why do developers write Custom class loaders, why not invoke a Bootstrap class loader to invoke your custom classes? What is the need to define custom class loaders? Why there are so many varieties of class loaders? eg:

how to build an APK and separate libraries that the app loads dynamically

前提是你 提交于 2019-11-27 11:28:39
The short summary is: How do I build an APK and separate libraries (by which I mean sets of classes (and ideally, resources too) in some form, such as JAR, AAR or DEX files), but not include those libraries in the APK; instead, the app loads them at run time? Detail So my main question is how to build such an app (e.g. Gradle configuration). How do I specify which classes go into which JAR or DEX files? Do I create an Android Studio module for each DEX file I want to end up with? A closely related question is how the Java code should then load the external libraries and access their classes at

Custom Class Loading in Dalvik with Gradle (Android New Build System)

為{幸葍}努か 提交于 2019-11-27 09:14:31
问题 As per the introduction of Custom Class Loading in Dalvik by Fred Chung on the Android Developers Blog: The Dalvik VM provides facilities for developers to perform custom class loading. Instead of loading Dalvik executable (“dex”) files from the default location, an application can load them from alternative locations such as internal storage or over the network. However, not many developers have the need to do custom class loading. But those who do and follow the instructions on that blog