classloader

android dexclassloader get list of all classes

倖福魔咒の 提交于 2019-12-03 12:54:02
I am using external jar from assets or sdcard in my android application. To do that I am using DexClassLoader. DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(), optimizedDexOutputPath.getAbsolutePath(), null, getClassLoader()); to load a class : Class myNewClass = cl.loadClass("com.example.dex.lib.LibraryProvider"); it works really nice but now I want to get list of all classes names in my DexClassLoader I found this to work in java but there is no such thing in android. Question is how i can get list of all classes names from DexClassLoader To list all classes

How does a classloader load classes reference in the manifest classpath?

折月煮酒 提交于 2019-12-03 12:50:26
I used maven to built a jar with an external classpath additions using addClasspath . When I run that jar using java -jar artifact.jar it is able to load classes from that main jar and from all jars in the libs directory. However if I ask the system property java.class.path it will only list the main jar. If I ask the system class loader for its urls ( ClassLoader.getSystemClassLoader().getURLs() ) it will also only return the main jar. If I ask any class contained in some library for its class loader it will return the system class loader. How is the system class loader able to load those

Difference between loading a class and instantiating it

穿精又带淫゛_ 提交于 2019-12-03 12:03:01
Could someone explain what is the difference between Class loading and instantiating a Class. When we load a class with Static variable does it also get instantiated the same time the Class get loaded? After all static code is part of the class rather than it's individual instances. It would be helpful if someone provided an example to help me understand this better. Here is some nice explanation(with an example and observation) When a class is loaded and initialized in JVM - Java When Class is loaded in Java Class loading is done by ClassLoaders in Java which can be implemented to eagerly

java.lang.IllegalAccessError: tried to access field ConcreteEntity.instance from class Entity

家住魔仙堡 提交于 2019-12-03 11:58:08
问题 java.lang.IllegalAccessError: tried to access field ConcreteEntity.instance from class Entity Ok so here is the deal. I am trying to access ConcreteEntity.instance which is a field with the access type default that exists inside the default ClassLoader and the Entity.getInstance is a method that exist in a child ClassLoader . Now keep in mind they're both in the same package, however an IllegalAccessError is being thrown. Is there a solution to this problem that doesn't involve me actually

Forcing class load

本秂侑毒 提交于 2019-12-03 11:17:14
Is there a way in C# or .net IL to force a class that has a type initializer (static constructor) to load itself, without accessing any of its parameters? Assuming I've got the class public static class LogInitialization { static LogInitialization() { System.Console.WriteLine("Initialized"); } } Is there a way to get this line to print? Note that the class is static so I can't instantiate it to force initialization, and it has no public members so I can't access them to start it. Rummaging in the CLI spec, I found a reference to the method RuntimeHelpers.RunClassConstructor If a language

Multiple instances of static variables

 ̄綄美尐妖づ 提交于 2019-12-03 11:02:43
I'm experimenting with using different classloaders to load a particular class, and see if the static variables in that class can have different instances. Basically, I'm trying to write code for what Stephen C has mentioned in this answer . Here are my classes: CustomClassLoader.java class CustomClassLoader extends ClassLoader { public Class loadClass(String classname) throws ClassNotFoundException { return super.loadClass(classname, true); } } Test.java (which contains the driver) class Test { public static void main(String[] args) throws Exception { CustomClassLoader c1 = new

How to config socks proxy in Java NIO

烂漫一生 提交于 2019-12-03 09:48:49
I'm developing a tool which includes forcing all network traffic of application to go across a socks proxy in Java. For old Socket API, I can just set system properties "-DsocksProxyHost=my-host -DsocksProxyPort=my-port", but it doesn't work with NIO. I tried a solution: I wrote an NIO SocketChannel, called "ProxySocketChannel" which extends SocketChannel. It contains socks connection and other socks proxy logic. But when I run it, I got an "IllegalSelectorException" in this line of code in "SelectorImpl.register": if (!(ch instanceof SelChImpl)) throw new IllegalSelectorException(); sun.nio

Reason and tracing of class loading during verification, method execution and JIT compilation

ぃ、小莉子 提交于 2019-12-03 08:59:24
I'm trying to understand which events lead to class loads on a very detailed basis and during my testing encountered one behaviour I do not understand in this very basic sample: public class ClinitTest { public static Integer num; public static Long NUMTEST; static { NUMTEST = new Long(15);; num = (int) (NUMTEST * 5); System.out.println(num); } public static void main(String[] args) { System.out.println( "The number is " + num); } } When running java.lang.Long gets loaded while executing the <clinit> . Well, it gets loaded earlier by bootstrap classloader but the AppClassloader is called at

How to launch jar with 'exec app_process' on android ICS

故事扮演 提交于 2019-12-03 08:59:06
I have 3 devices. 1.base on cm9(android 4.0.4). 2.htcg14(android 4.0.3) 3.moto me525 base on miui(android 2.2) they are all rooted. I exec the code below in the terminal on device 1 and 3,the process works fine. But device 2,it doesn't work. su export CLASSPATH=/sdcard/foo.jar exec app_process /system/bin xx.xx.Test '$@' log W/dalvikvm(12364): Exception Ljava/lang/NullPointerException; thrown while initializing Ljava/lang/System; W/dalvikvm(12364): Exception Ljava/lang/ExceptionInInitializerError; thrown while initializing Ljava/lang/ClassLoader$SystemClassLoader; W/dalvikvm(12364): WARNING:

Javassist: re-creating a class - delete first, or defrost() and modify?

早过忘川 提交于 2019-12-03 08:58:48
I use Javassist to create a class. And in a test suite, when a second test tries to create the same class, it fails at pool.makeClass( ... ) because the class is frozen (i.e. already created via toClass() . What's the way to overcome this? Ideally, the first test should delete the class somehow - perhaps unload from the classloader - but as I read in JLS , the unload operation is not reliable. So perhaps the workaround is to check in the class creating code whether it exists, and if it does, defrost() it, remove all members etc, and re-create it. Any other ideas? Or is there some reliable way