[
https://issues.jboss.org/browse/SHRINKWRAP-244?page=com.atlassian.jira.pl...
]
David Bosschaert commented on SHRINKWRAP-244:
---------------------------------------------
Hi Davide,
The main thing you need to do is get 2 classloaders. One that can load org.example.MyClass
(or whatever) and another that can't. There are many ways to do that, for example you
can do this by creating a jar file on disk with that class and then create a
URLClassLoader that can load from that jar.
Of the classloader that can't load the class you can use the current class's
classloader (as long as it doesn't load the org.example.MyClass).
Then:
1. create a SW Java Archive instance
2. Set TCCL to the one that *doesn't see* org.example.MyClass
3. Let's say jcl is the classloader that loads the jar file that holds
org.example.MyClass;
4. call archive.addClass("org.example.MyClass", jcl)
5. check the SW Java Archive.
For the other API the sequence is:
1. create a SW Java Archive instance
2. Set TCCL to the one that *doesn't see* org.example.MyClass
3. Let's say jcl is the classloader that loads the jar file that holds
org.example.MyClass;
4. Class<?> cls = jcl.loadClass("org.example.MyClass");
5. call archive.addClass(cls)
6. check the SW Java Archive.
This is off the top of my head, but in general that should do it.
Cheers,
David
When calling JavaArchiveImpl.addClass(String, ClassLoader) the TCCL
gets used instead
-------------------------------------------------------------------------------------
Key: SHRINKWRAP-244
URL:
https://issues.jboss.org/browse/SHRINKWRAP-244
Project: ShrinkWrap
Issue Type: Bug
Components: impl-base
Affects Versions: 1.0.0-alpha-12
Reporter: David Bosschaert
When I call JavaArchiveImpl.addClass(String fqcn, ClassLoader cl) the cl gets used to
load fqcn, but then further down the line, I find myself in ContainerBase.addPackages(),
which is called indirectly from the previous addClass method. The addPackages still uses
the TCCL while it should really use the cl passed in to the addClass method.
This also applies to JavaArchiveImpl.addClass(Class cls) where the classloader to be used
could be inferred from the cls argument, but instead the TCCL gets used...
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira