dev@glassfish.java.net

Re: [V3]Hwo to use forName from one bundle to another?

From: Sahoo <sahoo_at_sun.com>
Date: Fri, 06 Jun 2008 18:02:30 -0700

Kin-Man,

You are right in this case, adding dependency defeats the purpose of
using reflection. If it were an application class, then it is easily
solved by using thread's contextCL and it then becomes container's
responsibility to set the contextCL properly. Given that your code is
trying to a class from the environment where it is running in, why not
use a service approach? I see you already have an SPI, which is
ResourceInjector. Why not use something like /_at_Inject ResourceInjector
ri/; in your code?

Thanks,
Sahoo

Kin-man Chung wrote:
> Thanks for the tip. Adding the dependency on the bundle that
> contains the class used in forName seems to work, at least in
> glassfish.
>
> However, that totally defeats the purpose of using reflections
> in our case, because we don't know in general until runtime
> what class we need to load, hence the use of forName here.
> Other web containers may supply another class.
>
> We are trying to make JSP an independent project, and would like to
> avoid any dependency on glassfish conatiner. Having to added
> the dependencies used in forName seems to be going in the opposite
> direction. :-(
>
> -Kin-man
>
> Bhakti Mehta wrote:
>> Kin-man,
>> I ran into similar issue where I had a problem because the
>> AnnotationProcessorImpl which lies in common/annotation-framework
>> could not find Webservice class which is in javax.javaee module
>> I added the dependency in the annotation-framework pom.xml for
>> javax.javaee ( not committed as yet) and rebuilt that module
>> + <dependency>
>> + <groupId>org.glassfish</groupId>
>> + <artifactId>javax.javaee</artifactId>
>> + <version>${project.version}</version>
>> + </dependency>
>> Atleast that worked for me and I could make progress (working on the
>> next issue now)
>> If you then extract the MANIFEST of your target/*.jar in your module
>> you will have the updated info in it which has the necessary
>> HK2-Import-Bundles and Require-Bundle and that will mention this
>> additional dependency too
>> Hope that helps
>> Regards,
>> Bhakti
>>
>> Kin-man Chung wrote:
>>> Thanks Sahoo for clarifying loading of jars from a bundle that helped
>>> to solve my last problem. Now I have another. :-)
>>>
>>> The follow code fragment in org.apache.jasper.servlet.JspServlet
>>> used to work:
>>>
>>> String resourceInjectorClassName = config.getInitParameter(
>>> Constants.JSP_RESOURCE_INJECTOR_CONTEXT_ATTRIBUTE);
>>>
>>> if (resourceInjectorClassName != null) {
>>> try {
>>> ResourceInjector ri = (ResourceInjector)
>>>
>>> Class.forName(resourceInjectorClassName).newInstance();
>>> ri.setContext(this.context);
>>> this.context.setAttribute(
>>>
>>> Constants.JSP_RESOURCE_INJECTOR_CONTEXT_ATTRIBUTE, ri);
>>> } catch (Exception e) {
>>> throw new ServletException(e);
>>> }
>>> }
>>>
>>> Now I am getting a CNFE:
>>>
>>> java.lang.ClassNotFoundException:
>>> com.sun.enterprise.web.jsp.ResourceInjectorImpl
>>> at
>>> org.apache.felix.framework.searchpolicy.R4SearchPolicyCore.findClass(R4SearchPolicyCore.java:200)
>>>
>>> at
>>> org.apache.felix.framework.searchpolicy.R4SearchPolicy.findClass(R4SearchPolicy.java:45)
>>>
>>> at
>>> org.apache.felix.framework.searchpolicy.ContentClassLoader.loadClass(ContentClassLoader.java:109)
>>>
>>> at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
>>> at
>>> java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
>>> at java.lang.Class.forName0(Native Method)
>>> at java.lang.Class.forName(Class.java:169)
>>> at
>>> org.apache.jasper.servlet.JspServlet.init(JspServlet.java:158)
>>> at
>>> org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1213)
>>>
>>> at
>>> org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1043)
>>>
>>>
>>> Is this caused by the fact that
>>> com.sun.enterprise.web.jsp.ResourceInjectorImpl and
>>> org.apache.jasper.servlet.JspServlet are now in two different bundles?
>>>
>>> What can I do? Thanks.
>>>
>>> -Kin-man
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>