SAE上部署Java应用,jar包冲突解决办法

原创作品,转载注明来源http://transdoc.iteye.com
Under Creative Commons

不少同学在SAE部署Java应用的时候都会遇到jar包冲突问题,对此官方文档中只是提到:
引用
为了避免jar包冲突,请在上传War包至SAE环境前删除servlet-api和xml-api相关的jar包
引用
Java 平台目前提供log4j自定义配置功能,使用log4j输出的日志可通过应用中的log4j.properties来配置。

即使按照官方指导做了,还是有很多疑问,比如SAE到底已经提供哪些jar包了?
transdoc博主通过部署一个最小可用war包后,通过在jsp简单的调用System.getenv()和System.getProperties()方法有了一些发现。
在System.getenv()获取的环境变量中包含了应用的appname、accesskey、secretkey等信息。而在System.getProperties()获取到的系统属性中更是包含了Java运行环境的一些参数,其中便有java.class.path值,直接指出了SAE已提供的jar包,现贴出如下:
引用
/usr/local/sae/jetty/lib/jetty-xml-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/servlet-api-2.5.jar
/usr/local/sae/jetty/lib/jetty-http-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/jetty-continuation-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/jetty-server-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/jetty-security-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/jetty-servlet-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/jetty-webapp-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/jetty-deploy-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/jetty-servlets-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/ext/sae-client/channel-online-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-client/fetchurl-online-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-client/kvdb-online-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-client/mail-online-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-client/push-online-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-client/sae-config-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-client/segment-online-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-client/share-online-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-client/sms.jar
/usr/local/sae/jetty/lib/ext/sae-client/spy-online-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-client/storage-online-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-client/taskqueue-online-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/commons-beanutils-1.8.3.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/commons-beanutils-bean-collections-1.8.3.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/commons-beanutils-core-1.8.3.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/commons-codec-1.4.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/commons-collections-3.2.1.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/commons-lang-2.6.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/commons-logging-1.1.1.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/ezmorph-1.0.6.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/httpclient-cache-4.1.2.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/httpcore-4.1.2.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/httpmime-4.1.2.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/json-lib-2.4-jdk15.jar
/usr/local/sae/jetty/lib/ext/sae-dependences/mysql-connector-java-5.0.8-bin.jar
/usr/local/sae/jetty/lib/ext/sae-handlers/sae-deploy-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-handlers/sae-facade-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-handlers/sae-hanlder-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-handlers/sae-log-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-handlers/sae-monitor-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-handlers/sae-rewrite-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-handlers/sae-security-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-handlers/sae-servlet-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-handlers/sae-session-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-handlers/sae-webapp-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-modify/httpclient-modify-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-modify/jedis-2.1.0.jar
/usr/local/sae/jetty/lib/ext/sae-modify/log4j-modify-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-modify/mail.jar
/usr/local/sae/jetty/lib/ext/sae-other/sae-inner-mc-1.0.jar
/usr/local/sae/jetty/lib/ext/sae-other/sae-token-1.0.jar
/usr/local/sae/jetty/lib/jsp/com.sun.el_1.0.0.v201004190952.jar
/usr/local/sae/jetty/lib/jsp/ecj-3.6.jar
/usr/local/sae/jetty/lib/jsp/javax.el_2.1.0.v201004190952.jar
/usr/local/sae/jetty/lib/jsp/javax.servlet.jsp_2.1.0.v201004190952.jar
/usr/local/sae/jetty/lib/jsp/javax.servlet.jsp.jstl_1.2.0.v201004190952.jar
/usr/local/sae/jetty/lib/jsp/jetty-jsp-2.1-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/jsp/org.apache.jasper.glassfish_2.1.0.v201007080150.jar
/usr/local/sae/jetty/lib/jsp/org.apache.taglibs.standard.glassfish_1.2.0.v201004190952.jar
/usr/local/sae/jetty/lib/jetty-policy-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/jetty-rewrite-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/jetty-util-7.4.3.v20110701.jar
/usr/local/sae/jetty/lib/jetty-io-7.4.3.v20110701.jar

很明显的,上面包含了jetty运行依赖包、servlet/jspAPI、xmlAPI、mail、sae-client对应官方提供的sae-local-x.x.x.jar、sae运行依赖包、mysql驱动等,如果我们的war包里有冲突的包,则必须删除掉。
值得注意的是httpclient-modify-1.0.jar、log4j-modify-1.0.jar两个包经过了修改。而如果要使用“日志中心”的日志查看功能,那么就必须得用log4j作为日志输出端。
transdoc应用内使用了slf4j做日志接口,而依赖的开源jar包有使用slf4j的、有使用JCL的,这些接口都需要统一定向到log4j的控制台输出。
附件给出了transdoc的pom.xml,对SAE已提供的jar设置<scope>provided</scope>即可不打入war包中,有兴趣的同学可以下载下来参考参考。

原创作品,转载注明来源http://transdoc.iteye.com
Under Creative Commons

猜你喜欢

转载自transdoc.iteye.com/blog/2168609
今日推荐