Aquatic Safaris
Aquatic Safaris

Reputation: 11

tomcat 7 application migration to tomcat 8

I'm trying to deploy an application in tomcat 8 with the following xml file:

<?xml version='1.0' encoding='utf-8'?>
<Context docBase="/home/httpd/chAdmin" path="/chAdmin">
<Loader className="org.apache.catalina.loader.VirtualWebappLoader"
        virtualClasspath="/usr/local/calendar/libs/google-api-client-1.19.0.jar;/usr/local/calendar/google-api-services-calendar-v3-rev107-1.19.0.jar;/usr/local/calendar/libs/google-http-client-1.19.0.jar;/usr/local/calendar/libs/google-http-client-jackson2-1.19.0.jar;/usr/local/calendar/libs/google-oauth-client-1.19.0.jar;/usr/local/calendar/libs/jackson-core-2.1.3.jar"/>
</Context>

I've read a lot about the migration to the Resource methods and have changed the xml file to:

<?xml version='1.0' encoding='utf-8'?>
<Context docBase="/home/httpd/chAdmin" path="/chAdmin">
    <Resources className="org.apache.catalina.webresources.StandardRoot">
        <JarResources className="org.apache.catalina.webresources.JarResourceSet"
            base="/usr/local/calendar/libs/google-api-client-1.19.0.jar" webAppMount="/" />
        <JarResources className="org.apache.catalina.webresources.JarResourceSet"
            base="/usr/local/calendar/google-api-services-calendar-v3-rev107-1.19.0.jar" webAppMount="/" />
        <JarResources className="org.apache.catalina.webresources.JarResourceSet"
            base="/usr/local/calendar/libs/google-http-client-1.19.0.jar" webAppMount="/" />
        <JarResources className="org.apache.catalina.webresources.JarResourceSet"
            base="/usr/local/calendar/libs/google-http-client-jackson2-1.19.0.jar" webAppMount="/" />
        <JarResources className="org.apache.catalina.webresources.JarResourceSet"
            base="/usr/local/calendar/libs/google-oauth-client-1.19.0.jar" webAppMount="/" />
        <JarResources className="org.apache.catalina.webresources.JarResourceSet"
            base="/usr/local/calendar/libs/jackson-core-2.1.3.jar" webAppMount="/" />
    </Resources>
</Context>

The app is starting OK but is not importing the classes from the jar files. I'm sure I'm missing something here and cannot find a good example on how to do this. Please help.

My JSP will not compile and is throwing

org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: [20] in the generated java file: [/usr/local/apache-tomcat-8.0.30/work/Catalina/localhost/chAdmin/org/apache/jsp/charters_jsp.java] Only a type can be imported. com.google.api.client.json.JsonFactory resolves to a package

Apparently this means that the jar file is not importing correctly because com/google/api/client/json/JsonFactory.class is in google-http-client-1.19.0.jar

Upvotes: 1

Views: 1836

Answers (3)

Krish
Krish

Reputation: 1

I tried to override the classes by adding the below Postresources tag in context.xml but it didn't help. Any other thoughts on how to override classes in the exploded war file with the external class files.

<PostResources className="org.apache.catalina.webresources.DirResourceSet"
                        base="/workspace/MY_UTIL_PROJECT/WebContent/WEB-INF/classes"
                        webAppMount="/WEB-INF/classes">
                </PostResources>

Upvotes: 0

dutoitns
dutoitns

Reputation: 2273

OP, try using WEB-INF/lib as your webAppMount

An example:

Please note the comments inside and note that I used PostResources and not PreResources so that I can override classes in my current project if I'm not happy with my "util" implementation. I'm not actually sure if JarResource is treated as a "PostResource" or "PreResource" but overriding static content and classes works.

    <!--
         https://tomcat.apache.org/tomcat-8.0-doc/config/resources.html
         http://stackoverflow.com/questions/23143697/adding-external-resources-to-class-path-in-tomcat-8
         http://stackoverflow.com/questions/34515852/tomcat-7-application-migration-to-tomcat-8
         http://mikusa.blogspot.co.za/2014/07/tips-on-migrating-to-tomat-8-resources.html
    -->
    <Context path="/MY_PROJECT" docBase="/MY_PROJECT">
        <Resources className="org.apache.catalina.webresources.StandardRoot">
            <!-- Post-load the static content from my util project -->
            <PostResources className="org.apache.catalina.webresources.DirResourceSet"
                    base="/workspace/MY_UTIL_PROJECT/WebContent"
                    webAppMount="/">
            </PostResources>
            <!-- Post-load the classes from my util project -->
            <PostResources className="org.apache.catalina.webresources.DirResourceSet"
                    base="/workspace/MY_UTIL_PROJECT/WebContent/WEB-INF/classes"
                    webAppMount="/WEB-INF/classes">
            </PostResources>
            <!-- Load the JARs contained within my util project -->
            <JarResources className="org.apache.catalina.webresources.DirResourceSet"
                    base="/workspace/MY_UTIL_PROJECT/WebContent/WEB-INF/lib"
                    webAppMount="/WEB-INF/lib">
            </JarResources>
        </Resources>
    </Context>

Upvotes: 0

tfandango
tfandango

Reputation: 133

I found this while searching for my missing jar issue, I got it to work by changing the webAppMount to WEB-INF/classes, like this

<JarResources className="org.apache.catalina.webresources.JarResourceSet"
        base="/usr/local/calendar/libs/google-http-client-1.19.0.jar" webAppMount="/WEB-INF/classes" />

Upvotes: 2

Related Questions