You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Hassan Khan <ha...@gmail.com> on 2017/06/01 15:26:43 UTC

Re: Custom Webapp loading..

Any pointers to the problem .. pls... Have extended webapploader and use
the below function for adding jar in tomcat 6... for tomcat 8.5 the jar are
loading but not getting included in the classpath somehow...
/**
     * reflectively add a jar to the classloader. This only works when
called after super.start() has completed.
     */
    private void addJar(final File jarRealFile) {
        try {
            final String jarPath = getFilePathRelativeToBase(jarRealFile);
            final JarFile jarFile = new JarFile(jarRealFile);
            final ClassLoader cl = getClassLoader();
            if (cl instanceof WebappClassLoader) {
                final WebappClassLoader wcl = (WebappClassLoader) cl;
                final Class<?> clazz = WebappClassLoader.class;
                final Method addJar = clazz.getDeclaredMethod("addJar", new
Class[]{String.class, JarFile.class, File.class});
                addJar.setAccessible(true);
                addJar.invoke(wcl, jarPath, jarFile, jarRealFile);
            }
            log("added jar " + jarRealFile.getCanonicalPath());
        }
        catch (IOException e) {
            log("Exception accessing jar file: " + jarRealFile + ": " +
e.getMessage());
        }
        catch (SecurityException e) {
            log("Exception finding method in WebappClassLoader to add jar
file: " + jarRealFile + ": " + e.getMessage());
        }
        catch (NoSuchMethodException e) {
            log("Exception finding method in WebappClassLoader to add jar
file: " + jarRealFile + ": " + e.getMessage());
        }
        catch (IllegalArgumentException e) {
            log("Exception calling method in WebappClassLoader to add jar
file: " + jarRealFile + ": " + e.getMessage());
        }
        catch (IllegalAccessException e) {
            log("Exception calling method in WebappClassLoader to add jar
file: " + jarRealFile + ": " + e.getMessage());
        }
        catch (InvocationTargetException e) {
            log("Exception calling method in WebappClassLoader to add jar
file: " + jarRealFile + ": " + e.getMessage());
        }
    }

Thanks




On Wed, May 31, 2017 at 5:13 PM, Hassan Khan <ha...@gmail.com>
wrote:

> So the precise exception is Only a type can be imported. ABC resolves to a
> package..
>
> Stacktrace is :
>     at org.apache.jasper.compiler.DefaultErrorHandler.javacError(
> DefaultErrorHandler.java:102)
>     at org.apache.jasper.compiler.ErrorDispatcher.javacError(
> ErrorDispatcher.java:212)
>     at org.apache.jasper.compiler.JDTCompiler.generateClass(
> JDTCompiler.java:457)
>     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:377)
>     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
>     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:333)
>     at org.apache.jasper.JspCompilationContext.compile(
> JspCompilationContext.java:600)
>     at org.apache.jasper.servlet.JspServletWrapper.service(
> JspServletWrapper.java:368)
>     at org.apache.jasper.servlet.JspServlet.serviceJspFile(
> JspServlet.java:385)
>     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
>     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
> ApplicationFilterChain.java:231)
>     at org.apache.catalina.core.ApplicationFilterChain.doFilter(
> ApplicationFilterChain.java:166)
>     at org.apache.catalina.core.ApplicationDispatcher.invoke(
> ApplicationDispatcher.java:728)
>     at org.apache.catalina.core.ApplicationDispatcher.doInclude(
> ApplicationDispatcher.java:590)
>     at org.apache.catalina.core.ApplicationDispatcher.include(
> ApplicationDispatcher.java:524)
>     at org.apache.jasper.runtime.JspRuntimeLibrary.include(
> JspRuntimeLibrary.java:895)
>     at org.apache.jsp.iNexx.common._005fshinglesTop_jsp._
> jspService(_005fshinglesTop_jsp.java:385) ==> JSP page called from the
> main webapp referencing the modular apps
>
>
>
> On Wed, May 31, 2017 at 5:05 PM, Hassan Khan <ha...@gmail.com>
> wrote:
>
>> Hi,
>>
>> We have a main webapp (Tomcat\Webapp) that has many modular webapps (
>> (Tomcat\Webapp\app\) under it that can be removed and added by the user.
>> The main webapp has the service and connectors , but the modular webapps
>> do not need it.
>>
>> The problem is currently when the main webapp tries to access a jar in
>> the modular webapps lib dir... we have a class not found exception.. that
>> is why we need to load the jars from the modular webapps Web-INF\lib
>> directory.
>>
>> Thanks
>>
>>
>>
>> On Wed, May 31, 2017 at 5:00 PM, Aurélien Terrestris <
>> aterrestris@gmail.com> wrote:
>>
>>> hi
>>>
>>> what are you trying to do exactly ?
>>>
>>> If you just need to start one webapp after another one in a precise
>>> order,
>>> you need as many Services (+Connector on a different port, + Host) as
>>> webapps.
>>>
>>> A.T.
>>>
>>>
>>>
>>>
>>>
>>> 2017-05-31 22:48 GMT+02:00 Hassan Khan <ha...@gmail.com>:
>>>
>>> > Hi,
>>> >
>>> > We have the following structure for webapps in tomcat 6.
>>> >
>>> > Tomcat > Webapp > Application 1 >WEB-INF >lib
>>> > Tomcat > Webapp > Application 1 > Application >WEB-INF> lib
>>> >
>>> >
>>> > The  Tomcat > Webapp > Application 1 >WEB-INF >lib gets loaded with
>>> > addwebapp() function..
>>> > but for Tomcat > Webapp > Application 1 > Application >WEB-INF> lib ,
>>> we
>>> > wrote a custom webapploader that extended WebappLoader.
>>> >
>>> > Now we are upgrading to tomcat 8.5....
>>> >
>>> > Wanted to know if any other way to accomplish the same task.
>>> >
>>> > Was working on using the same extended loader .. but the start()
>>> function
>>> > has changed to InternalStart() and getting a exception as below:
>>> > Caused by: org.apache.catalina.LifecycleException: An invalid
>>> Lifecycle
>>> > transition was attempted ([after_start]) for component
>>> > [WebappLoader[/SandBox/Primar]] in state [STARTING_PREP]
>>> >
>>> >  Any pointer are appreciated.. not that familiar with extending apache
>>> > classes.
>>> >
>>> > Thanks
>>> > Hassan
>>> >
>>> >
>>> >
>>> >
>>> > On Wed, May 31, 2017 at 4:42 PM, Hassan Khan <ha...@gmail.com>
>>> > wrote:
>>> >
>>> > > Hi,
>>> > >
>>> > > We have the following structure for webapp in tomcat 6.
>>> > >
>>> > > Tomcat > Webapp > Application 1 > Application >WEB-INF> lib
>>> > >
>>> > > T
>>> > > he Alpp
>>> > >
>>> > > --
>>> > > Hassan Khan
>>> > >
>>> >
>>> >
>>> >
>>> > --
>>> > Hassan Khan
>>> >
>>>
>>
>>
>>
>> --
>> Hassan Khan
>>
>
>
>
> --
> Hassan Khan
>



-- 
Hassan Khan

Re: Custom Webapp loading..

Posted by Hassan Khan <ha...@gmail.com>.
Thanks a lot Violeta....

Adding the following code , It did the trick for embedded tomcat program...
        List<File> filterdJarfiles = getAppJarFilesAlone(folderName);

        WebResourceRoot resources = new StandardRoot(contextNew);
        for(File jf:filterdJarfiles){
           String st =
jf.getAbsolutePath().substring(0,jf.getAbsolutePath().lastIndexOf(File.separator));
           resources.addPreResources(new DirResourceSet(resources,
"/WEB-INF/lib",
                     st, "/"));
        }

        contextNew.setResources(resources);
        CustomLoader loader= new
CustomLoader(contextNew.getParentClassLoader(),contextNew);
        contextNew.setLoader(loader);

But required to set the loader though..


Thanks a lot...

Hassan

On Fri, Jun 2, 2017 at 6:40 AM, Violeta Georgieva <vi...@apache.org>
wrote:

> Hi,
>
> 2017-06-01 18:26 GMT+03:00 Hassan Khan <ha...@gmail.com>:
> >
> > Any pointers to the problem .. pls... Have extended webapploader and use
>
> Instead of extending the class loader you might consider the new Web
> Application Resources feature:
> http://tomcat.apache.org/tomcat-8.5-doc/config/resources.html
>
> Regards,
> Violeta
>
> > the below function for adding jar in tomcat 6... for tomcat 8.5 the jar
> are
> > loading but not getting included in the classpath somehow...
> > /**
> >      * reflectively add a jar to the classloader. This only works when
> > called after super.start() has completed.
> >      */
> >     private void addJar(final File jarRealFile) {
> >         try {
> >             final String jarPath = getFilePathRelativeToBase(
> jarRealFile);
> >             final JarFile jarFile = new JarFile(jarRealFile);
> >             final ClassLoader cl = getClassLoader();
> >             if (cl instanceof WebappClassLoader) {
> >                 final WebappClassLoader wcl = (WebappClassLoader) cl;
> >                 final Class<?> clazz = WebappClassLoader.class;
> >                 final Method addJar = clazz.getDeclaredMethod("addJar",
> new
> > Class[]{String.class, JarFile.class, File.class});
> >                 addJar.setAccessible(true);
> >                 addJar.invoke(wcl, jarPath, jarFile, jarRealFile);
> >             }
> >             log("added jar " + jarRealFile.getCanonicalPath());
> >         }
> >         catch (IOException e) {
> >             log("Exception accessing jar file: " + jarRealFile + ": " +
> > e.getMessage());
> >         }
> >         catch (SecurityException e) {
> >             log("Exception finding method in WebappClassLoader to add jar
> > file: " + jarRealFile + ": " + e.getMessage());
> >         }
> >         catch (NoSuchMethodException e) {
> >             log("Exception finding method in WebappClassLoader to add jar
> > file: " + jarRealFile + ": " + e.getMessage());
> >         }
> >         catch (IllegalArgumentException e) {
> >             log("Exception calling method in WebappClassLoader to add jar
> > file: " + jarRealFile + ": " + e.getMessage());
> >         }
> >         catch (IllegalAccessException e) {
> >             log("Exception calling method in WebappClassLoader to add jar
> > file: " + jarRealFile + ": " + e.getMessage());
> >         }
> >         catch (InvocationTargetException e) {
> >             log("Exception calling method in WebappClassLoader to add jar
> > file: " + jarRealFile + ": " + e.getMessage());
> >         }
> >     }
> >
> > Thanks
> >
> >
> >
> >
> > On Wed, May 31, 2017 at 5:13 PM, Hassan Khan <ha...@gmail.com>
> > wrote:
> >
> > > So the precise exception is Only a type can be imported. ABC resolves
> to a
> > > package..
> > >
> > > Stacktrace is :
> > >     at org.apache.jasper.compiler.DefaultErrorHandler.javacError(
> > > DefaultErrorHandler.java:102)
> > >     at org.apache.jasper.compiler.ErrorDispatcher.javacError(
> > > ErrorDispatcher.java:212)
> > >     at org.apache.jasper.compiler.JDTCompiler.generateClass(
> > > JDTCompiler.java:457)
> > >     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:377)
> > >     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
> > >     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:333)
> > >     at org.apache.jasper.JspCompilationContext.compile(
> > > JspCompilationContext.java:600)
> > >     at org.apache.jasper.servlet.JspServletWrapper.service(
> > > JspServletWrapper.java:368)
> > >     at org.apache.jasper.servlet.JspServlet.serviceJspFile(
> > > JspServlet.java:385)
> > >     at org.apache.jasper.servlet.JspServlet.service(JspServlet.
> java:329)
> > >     at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
> > >     at org.apache.catalina.core.ApplicationFilterChain.
> internalDoFilter(
> > > ApplicationFilterChain.java:231)
> > >     at org.apache.catalina.core.ApplicationFilterChain.doFilter(
> > > ApplicationFilterChain.java:166)
> > >     at org.apache.catalina.core.ApplicationDispatcher.invoke(
> > > ApplicationDispatcher.java:728)
> > >     at org.apache.catalina.core.ApplicationDispatcher.doInclude(
> > > ApplicationDispatcher.java:590)
> > >     at org.apache.catalina.core.ApplicationDispatcher.include(
> > > ApplicationDispatcher.java:524)
> > >     at org.apache.jasper.runtime.JspRuntimeLibrary.include(
> > > JspRuntimeLibrary.java:895)
> > >     at org.apache.jsp.iNexx.common._005fshinglesTop_jsp._
> > > jspService(_005fshinglesTop_jsp.java:385) ==> JSP page called from the
> > > main webapp referencing the modular apps
> > >
> > >
> > >
> > > On Wed, May 31, 2017 at 5:05 PM, Hassan Khan <ha...@gmail.com>
> > > wrote:
> > >
> > >> Hi,
> > >>
> > >> We have a main webapp (Tomcat\Webapp) that has many modular webapps (
> > >> (Tomcat\Webapp\app\) under it that can be removed and added by the
> user.
> > >> The main webapp has the service and connectors , but the modular
> webapps
> > >> do not need it.
> > >>
> > >> The problem is currently when the main webapp tries to access a jar in
> > >> the modular webapps lib dir... we have a class not found exception..
> that
> > >> is why we need to load the jars from the modular webapps Web-INF\lib
> > >> directory.
> > >>
> > >> Thanks
> > >>
> > >>
> > >>
> > >> On Wed, May 31, 2017 at 5:00 PM, Aurélien Terrestris <
> > >> aterrestris@gmail.com> wrote:
> > >>
> > >>> hi
> > >>>
> > >>> what are you trying to do exactly ?
> > >>>
> > >>> If you just need to start one webapp after another one in a precise
> > >>> order,
> > >>> you need as many Services (+Connector on a different port, + Host) as
> > >>> webapps.
> > >>>
> > >>> A.T.
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>> 2017-05-31 22:48 GMT+02:00 Hassan Khan <ha...@gmail.com>:
> > >>>
> > >>> > Hi,
> > >>> >
> > >>> > We have the following structure for webapps in tomcat 6.
> > >>> >
> > >>> > Tomcat > Webapp > Application 1 >WEB-INF >lib
> > >>> > Tomcat > Webapp > Application 1 > Application >WEB-INF> lib
> > >>> >
> > >>> >
> > >>> > The  Tomcat > Webapp > Application 1 >WEB-INF >lib gets loaded with
> > >>> > addwebapp() function..
> > >>> > but for Tomcat > Webapp > Application 1 > Application >WEB-INF> lib
> ,
> > >>> we
> > >>> > wrote a custom webapploader that extended WebappLoader.
> > >>> >
> > >>> > Now we are upgrading to tomcat 8.5....
> > >>> >
> > >>> > Wanted to know if any other way to accomplish the same task.
> > >>> >
> > >>> > Was working on using the same extended loader .. but the start()
> > >>> function
> > >>> > has changed to InternalStart() and getting a exception as below:
> > >>> > Caused by: org.apache.catalina.LifecycleException: An invalid
> > >>> Lifecycle
> > >>> > transition was attempted ([after_start]) for component
> > >>> > [WebappLoader[/SandBox/Primar]] in state [STARTING_PREP]
> > >>> >
> > >>> >  Any pointer are appreciated.. not that familiar with extending
> apache
> > >>> > classes.
> > >>> >
> > >>> > Thanks
> > >>> > Hassan
> > >>> >
> > >>> >
> > >>> >
> > >>> >
> > >>> > On Wed, May 31, 2017 at 4:42 PM, Hassan Khan <
> hassankhan986@gmail.com>
> > >>> > wrote:
> > >>> >
> > >>> > > Hi,
> > >>> > >
> > >>> > > We have the following structure for webapp in tomcat 6.
> > >>> > >
> > >>> > > Tomcat > Webapp > Application 1 > Application >WEB-INF> lib
> > >>> > >
> > >>> > > T
> > >>> > > he Alpp
> > >>> > >
> > >>> > > --
> > >>> > > Hassan Khan
> > >>> > >
> > >>> >
> > >>> >
> > >>> >
> > >>> > --
> > >>> > Hassan Khan
> > >>> >
> > >>>
> > >>
> > >>
> > >>
> > >> --
> > >> Hassan Khan
> > >>
> > >
> > >
> > >
> > > --
> > > Hassan Khan
> > >
> >
> >
> >
> > --
> > Hassan Khan
>



-- 
Hassan Khan

Re: Custom Webapp loading..

Posted by Violeta Georgieva <vi...@apache.org>.
Hi,

2017-06-01 18:26 GMT+03:00 Hassan Khan <ha...@gmail.com>:
>
> Any pointers to the problem .. pls... Have extended webapploader and use

Instead of extending the class loader you might consider the new Web
Application Resources feature:
http://tomcat.apache.org/tomcat-8.5-doc/config/resources.html

Regards,
Violeta

> the below function for adding jar in tomcat 6... for tomcat 8.5 the jar
are
> loading but not getting included in the classpath somehow...
> /**
>      * reflectively add a jar to the classloader. This only works when
> called after super.start() has completed.
>      */
>     private void addJar(final File jarRealFile) {
>         try {
>             final String jarPath = getFilePathRelativeToBase(jarRealFile);
>             final JarFile jarFile = new JarFile(jarRealFile);
>             final ClassLoader cl = getClassLoader();
>             if (cl instanceof WebappClassLoader) {
>                 final WebappClassLoader wcl = (WebappClassLoader) cl;
>                 final Class<?> clazz = WebappClassLoader.class;
>                 final Method addJar = clazz.getDeclaredMethod("addJar",
new
> Class[]{String.class, JarFile.class, File.class});
>                 addJar.setAccessible(true);
>                 addJar.invoke(wcl, jarPath, jarFile, jarRealFile);
>             }
>             log("added jar " + jarRealFile.getCanonicalPath());
>         }
>         catch (IOException e) {
>             log("Exception accessing jar file: " + jarRealFile + ": " +
> e.getMessage());
>         }
>         catch (SecurityException e) {
>             log("Exception finding method in WebappClassLoader to add jar
> file: " + jarRealFile + ": " + e.getMessage());
>         }
>         catch (NoSuchMethodException e) {
>             log("Exception finding method in WebappClassLoader to add jar
> file: " + jarRealFile + ": " + e.getMessage());
>         }
>         catch (IllegalArgumentException e) {
>             log("Exception calling method in WebappClassLoader to add jar
> file: " + jarRealFile + ": " + e.getMessage());
>         }
>         catch (IllegalAccessException e) {
>             log("Exception calling method in WebappClassLoader to add jar
> file: " + jarRealFile + ": " + e.getMessage());
>         }
>         catch (InvocationTargetException e) {
>             log("Exception calling method in WebappClassLoader to add jar
> file: " + jarRealFile + ": " + e.getMessage());
>         }
>     }
>
> Thanks
>
>
>
>
> On Wed, May 31, 2017 at 5:13 PM, Hassan Khan <ha...@gmail.com>
> wrote:
>
> > So the precise exception is Only a type can be imported. ABC resolves
to a
> > package..
> >
> > Stacktrace is :
> >     at org.apache.jasper.compiler.DefaultErrorHandler.javacError(
> > DefaultErrorHandler.java:102)
> >     at org.apache.jasper.compiler.ErrorDispatcher.javacError(
> > ErrorDispatcher.java:212)
> >     at org.apache.jasper.compiler.JDTCompiler.generateClass(
> > JDTCompiler.java:457)
> >     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:377)
> >     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
> >     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:333)
> >     at org.apache.jasper.JspCompilationContext.compile(
> > JspCompilationContext.java:600)
> >     at org.apache.jasper.servlet.JspServletWrapper.service(
> > JspServletWrapper.java:368)
> >     at org.apache.jasper.servlet.JspServlet.serviceJspFile(
> > JspServlet.java:385)
> >     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
> >     at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
> >     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
> > ApplicationFilterChain.java:231)
> >     at org.apache.catalina.core.ApplicationFilterChain.doFilter(
> > ApplicationFilterChain.java:166)
> >     at org.apache.catalina.core.ApplicationDispatcher.invoke(
> > ApplicationDispatcher.java:728)
> >     at org.apache.catalina.core.ApplicationDispatcher.doInclude(
> > ApplicationDispatcher.java:590)
> >     at org.apache.catalina.core.ApplicationDispatcher.include(
> > ApplicationDispatcher.java:524)
> >     at org.apache.jasper.runtime.JspRuntimeLibrary.include(
> > JspRuntimeLibrary.java:895)
> >     at org.apache.jsp.iNexx.common._005fshinglesTop_jsp._
> > jspService(_005fshinglesTop_jsp.java:385) ==> JSP page called from the
> > main webapp referencing the modular apps
> >
> >
> >
> > On Wed, May 31, 2017 at 5:05 PM, Hassan Khan <ha...@gmail.com>
> > wrote:
> >
> >> Hi,
> >>
> >> We have a main webapp (Tomcat\Webapp) that has many modular webapps (
> >> (Tomcat\Webapp\app\) under it that can be removed and added by the
user.
> >> The main webapp has the service and connectors , but the modular
webapps
> >> do not need it.
> >>
> >> The problem is currently when the main webapp tries to access a jar in
> >> the modular webapps lib dir... we have a class not found exception..
that
> >> is why we need to load the jars from the modular webapps Web-INF\lib
> >> directory.
> >>
> >> Thanks
> >>
> >>
> >>
> >> On Wed, May 31, 2017 at 5:00 PM, Aurélien Terrestris <
> >> aterrestris@gmail.com> wrote:
> >>
> >>> hi
> >>>
> >>> what are you trying to do exactly ?
> >>>
> >>> If you just need to start one webapp after another one in a precise
> >>> order,
> >>> you need as many Services (+Connector on a different port, + Host) as
> >>> webapps.
> >>>
> >>> A.T.
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> 2017-05-31 22:48 GMT+02:00 Hassan Khan <ha...@gmail.com>:
> >>>
> >>> > Hi,
> >>> >
> >>> > We have the following structure for webapps in tomcat 6.
> >>> >
> >>> > Tomcat > Webapp > Application 1 >WEB-INF >lib
> >>> > Tomcat > Webapp > Application 1 > Application >WEB-INF> lib
> >>> >
> >>> >
> >>> > The  Tomcat > Webapp > Application 1 >WEB-INF >lib gets loaded with
> >>> > addwebapp() function..
> >>> > but for Tomcat > Webapp > Application 1 > Application >WEB-INF> lib
,
> >>> we
> >>> > wrote a custom webapploader that extended WebappLoader.
> >>> >
> >>> > Now we are upgrading to tomcat 8.5....
> >>> >
> >>> > Wanted to know if any other way to accomplish the same task.
> >>> >
> >>> > Was working on using the same extended loader .. but the start()
> >>> function
> >>> > has changed to InternalStart() and getting a exception as below:
> >>> > Caused by: org.apache.catalina.LifecycleException: An invalid
> >>> Lifecycle
> >>> > transition was attempted ([after_start]) for component
> >>> > [WebappLoader[/SandBox/Primar]] in state [STARTING_PREP]
> >>> >
> >>> >  Any pointer are appreciated.. not that familiar with extending
apache
> >>> > classes.
> >>> >
> >>> > Thanks
> >>> > Hassan
> >>> >
> >>> >
> >>> >
> >>> >
> >>> > On Wed, May 31, 2017 at 4:42 PM, Hassan Khan <
hassankhan986@gmail.com>
> >>> > wrote:
> >>> >
> >>> > > Hi,
> >>> > >
> >>> > > We have the following structure for webapp in tomcat 6.
> >>> > >
> >>> > > Tomcat > Webapp > Application 1 > Application >WEB-INF> lib
> >>> > >
> >>> > > T
> >>> > > he Alpp
> >>> > >
> >>> > > --
> >>> > > Hassan Khan
> >>> > >
> >>> >
> >>> >
> >>> >
> >>> > --
> >>> > Hassan Khan
> >>> >
> >>>
> >>
> >>
> >>
> >> --
> >> Hassan Khan
> >>
> >
> >
> >
> > --
> > Hassan Khan
> >
>
>
>
> --
> Hassan Khan

Re: Custom Webapp loading..

Posted by Hassan Khan <ha...@gmail.com>.
Also inside the work folder the jsp is not compiled , just the _folder name
has been created... does that point to a issue.
Thanks

On Thu, Jun 1, 2017 at 11:26 AM, Hassan Khan <ha...@gmail.com>
wrote:

> Any pointers to the problem .. pls... Have extended webapploader and use
> the below function for adding jar in tomcat 6... for tomcat 8.5 the jar are
> loading but not getting included in the classpath somehow...
> /**
>      * reflectively add a jar to the classloader. This only works when
> called after super.start() has completed.
>      */
>     private void addJar(final File jarRealFile) {
>         try {
>             final String jarPath = getFilePathRelativeToBase(jarRealFile);
>             final JarFile jarFile = new JarFile(jarRealFile);
>             final ClassLoader cl = getClassLoader();
>             if (cl instanceof WebappClassLoader) {
>                 final WebappClassLoader wcl = (WebappClassLoader) cl;
>                 final Class<?> clazz = WebappClassLoader.class;
>                 final Method addJar = clazz.getDeclaredMethod("addJar",
> new Class[]{String.class, JarFile.class, File.class});
>                 addJar.setAccessible(true);
>                 addJar.invoke(wcl, jarPath, jarFile, jarRealFile);
>             }
>             log("added jar " + jarRealFile.getCanonicalPath());
>         }
>         catch (IOException e) {
>             log("Exception accessing jar file: " + jarRealFile + ": " +
> e.getMessage());
>         }
>         catch (SecurityException e) {
>             log("Exception finding method in WebappClassLoader to add jar
> file: " + jarRealFile + ": " + e.getMessage());
>         }
>         catch (NoSuchMethodException e) {
>             log("Exception finding method in WebappClassLoader to add jar
> file: " + jarRealFile + ": " + e.getMessage());
>         }
>         catch (IllegalArgumentException e) {
>             log("Exception calling method in WebappClassLoader to add jar
> file: " + jarRealFile + ": " + e.getMessage());
>         }
>         catch (IllegalAccessException e) {
>             log("Exception calling method in WebappClassLoader to add jar
> file: " + jarRealFile + ": " + e.getMessage());
>         }
>         catch (InvocationTargetException e) {
>             log("Exception calling method in WebappClassLoader to add jar
> file: " + jarRealFile + ": " + e.getMessage());
>         }
>     }
>
> Thanks
>
>
>
>
> On Wed, May 31, 2017 at 5:13 PM, Hassan Khan <ha...@gmail.com>
> wrote:
>
>> So the precise exception is Only a type can be imported. ABC resolves to
>> a package..
>>
>> Stacktrace is :
>>     at org.apache.jasper.compiler.DefaultErrorHandler.javacError(De
>> faultErrorHandler.java:102)
>>     at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorD
>> ispatcher.java:212)
>>     at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTComp
>> iler.java:457)
>>     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:377)
>>     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
>>     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:333)
>>     at org.apache.jasper.JspCompilationContext.compile(JspCompilati
>> onContext.java:600)
>>     at org.apache.jasper.servlet.JspServletWrapper.service(JspServl
>> etWrapper.java:368)
>>     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServl
>> et.java:385)
>>     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
>>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
>>     at org.apache.catalina.core.ApplicationFilterChain.internalDoFi
>> lter(ApplicationFilterChain.java:231)
>>     at org.apache.catalina.core.ApplicationFilterChain.doFilter(App
>> licationFilterChain.java:166)
>>     at org.apache.catalina.core.ApplicationDispatcher.invoke(Applic
>> ationDispatcher.java:728)
>>     at org.apache.catalina.core.ApplicationDispatcher.doInclude(App
>> licationDispatcher.java:590)
>>     at org.apache.catalina.core.ApplicationDispatcher.include(Appli
>> cationDispatcher.java:524)
>>     at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRunti
>> meLibrary.java:895)
>>     at org.apache.jsp.iNexx.common._005fshinglesTop_jsp._jspService
>> (_005fshinglesTop_jsp.java:385) ==> JSP page called from the main webapp
>> referencing the modular apps
>>
>>
>>
>> On Wed, May 31, 2017 at 5:05 PM, Hassan Khan <ha...@gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> We have a main webapp (Tomcat\Webapp) that has many modular webapps (
>>> (Tomcat\Webapp\app\) under it that can be removed and added by the user.
>>> The main webapp has the service and connectors , but the modular webapps
>>> do not need it.
>>>
>>> The problem is currently when the main webapp tries to access a jar in
>>> the modular webapps lib dir... we have a class not found exception.. that
>>> is why we need to load the jars from the modular webapps Web-INF\lib
>>> directory.
>>>
>>> Thanks
>>>
>>>
>>>
>>> On Wed, May 31, 2017 at 5:00 PM, Aurélien Terrestris <
>>> aterrestris@gmail.com> wrote:
>>>
>>>> hi
>>>>
>>>> what are you trying to do exactly ?
>>>>
>>>> If you just need to start one webapp after another one in a precise
>>>> order,
>>>> you need as many Services (+Connector on a different port, + Host) as
>>>> webapps.
>>>>
>>>> A.T.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> 2017-05-31 22:48 GMT+02:00 Hassan Khan <ha...@gmail.com>:
>>>>
>>>> > Hi,
>>>> >
>>>> > We have the following structure for webapps in tomcat 6.
>>>> >
>>>> > Tomcat > Webapp > Application 1 >WEB-INF >lib
>>>> > Tomcat > Webapp > Application 1 > Application >WEB-INF> lib
>>>> >
>>>> >
>>>> > The  Tomcat > Webapp > Application 1 >WEB-INF >lib gets loaded with
>>>> > addwebapp() function..
>>>> > but for Tomcat > Webapp > Application 1 > Application >WEB-INF> lib
>>>> ,  we
>>>> > wrote a custom webapploader that extended WebappLoader.
>>>> >
>>>> > Now we are upgrading to tomcat 8.5....
>>>> >
>>>> > Wanted to know if any other way to accomplish the same task.
>>>> >
>>>> > Was working on using the same extended loader .. but the start()
>>>> function
>>>> > has changed to InternalStart() and getting a exception as below:
>>>> > Caused by: org.apache.catalina.LifecycleException: An invalid
>>>> Lifecycle
>>>> > transition was attempted ([after_start]) for component
>>>> > [WebappLoader[/SandBox/Primar]] in state [STARTING_PREP]
>>>> >
>>>> >  Any pointer are appreciated.. not that familiar with extending apache
>>>> > classes.
>>>> >
>>>> > Thanks
>>>> > Hassan
>>>> >
>>>> >
>>>> >
>>>> >
>>>> > On Wed, May 31, 2017 at 4:42 PM, Hassan Khan <hassankhan986@gmail.com
>>>> >
>>>> > wrote:
>>>> >
>>>> > > Hi,
>>>> > >
>>>> > > We have the following structure for webapp in tomcat 6.
>>>> > >
>>>> > > Tomcat > Webapp > Application 1 > Application >WEB-INF> lib
>>>> > >
>>>> > > T
>>>> > > he Alpp
>>>> > >
>>>> > > --
>>>> > > Hassan Khan
>>>> > >
>>>> >
>>>> >
>>>> >
>>>> > --
>>>> > Hassan Khan
>>>> >
>>>>
>>>
>>>
>>>
>>> --
>>> Hassan Khan
>>>
>>
>>
>>
>> --
>> Hassan Khan
>>
>
>
>
> --
> Hassan Khan
>



-- 
Hassan Khan