[
https://jira.jboss.org/jira/browse/WELDSE-25?page=com.atlassian.jira.plug...
]
Morten Christensen commented on WELDSE-25:
------------------------------------------
As for how I tried to use ResourceLoader, I added the class below to my app + make the
appropriate file under META-INF/services + called setClassLoader with the above class
loader from the OSGI activator (notice the use of a static variable which I don't
like).
In addition, when Weld SE ignored my class, I did a manual test in my Activator as follows
and it would my service - so my service was installed:
java.util.ServiceLoader<org.jboss.weld.resources.spi.ResourceLoader>
osgiServiceLoader =
java.util.ServiceLoader.load(org.jboss.weld.resources.spi.ResourceLoader.class);
Iterator<org.jboss.weld.resources.spi.ResourceLoader> iter =
osgiServiceLoader.iterator();
while (iter.hasNext())
System.out.println("Found ResourceLoader: "+iter.next());
My OSGI ResourceLoader loader below. Please be free to use this code for whatever purpose
you want.
public class OsgiLoader implements ResourceLoader
{
private static ClassLoader classLoader;
public static void setClassLoader(ClassLoader classLoader)
{
OsgiLoader.classLoader=classLoader;
}
public static void removeClassLoader()
{
OsgiLoader.classLoader=null;
}
public OsgiLoader()
{
System.err.println("OsgiLoader CTR called");
}
@Override
public Class<?> classForName(String name)
{
System.err.println("OsgiLoader.classForName called");
try {
return classLoader.loadClass(name);
} catch (ClassNotFoundException e)
{
throw new ResourceLoadingException(e);
} catch (NoClassDefFoundError e)
{
throw new ResourceLoadingException(e);
}
}
@Override
public URL getResource(String name) {
System.err.println("OsgiLoader.getResource called");
return classLoader.getResource(name);
}
@Override
public Collection<URL> getResources(String name) {
System.err.println("OsgiLoader.getResources called");
try {
return toCollection(classLoader.getResources(name));
} catch (IOException e) {
throw new ResourceLoadingException(e);
}
}
@Override
public void cleanup()
{
classLoader=null;
}
private static Collection<URL> toCollection(Enumeration<URL> urls) {
ArrayList<URL> urlCollection = new ArrayList<URL>();
while (urls.hasMoreElements())
urlCollection.add(urls.nextElement());
return urlCollection;
}
}
Weld SE ignores org.jboss.weld.resources.spi.ResourceLoader
-----------------------------------------------------------
Key: WELDSE-25
URL:
https://jira.jboss.org/jira/browse/WELDSE-25
Project: Weld support for Java SE
Issue Type: Bug
Affects Versions: 1.0.1.Final
Environment: Weld SE + Java 6
Reporter: Morten Christensen
Priority: Critical
According to the docs "org.jboss.weld.resources.spi.ResourceLoader" is
responsible for resource loading/class creation and if it worked it would appear to solve
a lot of potential integration problems, f.x. with OSGI (see issue 520).
Unfortunately, Weld SE does not apper to use ResourceLoaders and it ignores any
implementations of this service that the Java SE app supplies. Even worse, Weld SE
classloading behavior is hardcoded in
"org.jboss.weld.environment.se.util.Reflections". This makes it impossible to
use Weld SE where classloading does not work with the Thread's context class loader
such as OSGI etc.
Weld SE should be changed to look for service implementations of
"org.jboss.weld.resources.spi.ResourceLoader" (i.e. actually work according to
its own documentation).
P.S: It would also be nice if Weld SE would allow users to supply a Classloader to the
constructor for org.jboss.weld.environment.se.Weld
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira