我尝试使用以下xml文件在tomcat 8中部署应用程序:
<?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>
我已经阅读了很多有关迁移到Resource方法的内容,并将xml文件更改为:
<?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>
应用程序正在启动,但不会从jar文件中导入类。我确定我在这里遗漏了一些东西,但却找不到如何做到这一点的好例子。请帮忙。
我的JSP不会编译而且正在抛出
org.apache.jasper.JasperException:无法为JSP编译类: 生成的java文件中的行:[20]发生错误:[/usr/local/apache-tomcat-8.0.30/work/Catalina/localhost/chAdmin/org/apache/jsp/charters_jsp.java] 只能导入一种类型。 com.google.api.client.json.JsonFactory解析为包
显然这意味着jar文件无法正确导入,因为com / google / api / client / json / JsonFactory.class位于google-http-client-1.19.0.jar
答案 0 :(得分:2)
我在搜索我丢失的jar问题时发现了这个问题,我通过将webAppMount更改为WEB-INF /类来实现它,就像这样
<JarResources className="org.apache.catalina.webresources.JarResourceSet"
base="/usr/local/calendar/libs/google-http-client-1.19.0.jar" webAppMount="/WEB-INF/classes" />
答案 1 :(得分:0)
OP,尝试使用WEB-INF/lib
作为webAppMount
一个例子:
请注意里面的评论并注意我使用PostResources
而不是PreResources
,这样我就可以覆盖当前项目中的类,如果我对我的“util”实现不满意的话。我不确定JarResource
是被视为“PostResource”还是“PreResource”,但是重写静态内容和类是否有效。
<!--
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>
答案 2 :(得分:0)
我试图通过在context.xml中添加以下Postresources标记来覆盖这些类,但这没有帮助。关于如何用外部类文件覆盖爆炸的war文件中的类的任何其他想法。
<PostResources className="org.apache.catalina.webresources.DirResourceSet"
base="/workspace/MY_UTIL_PROJECT/WebContent/WEB-INF/classes"
webAppMount="/WEB-INF/classes">
</PostResources>