您的位置:首页 > 运维架构 > Tomcat

Java项目在Tomcat下能运行,到WAS上不能运行原因查找

2014-08-15 09:32 483 查看
0、分析原因:一般都是jar包冲突

1、定位错误:发布到WAS上定位错误的位置,找到哪行代码报的错误

找到错误位置为 Scheme sch = new Scheme("https", 443, sf);

即Scheme
所在的包产生冲突

2、Tomcat控制台输出:找到报错代码行,在控制台输出该行用的类所引用的jar包

//打印Scheme
所引用的Jar包

String jarFilePath = Scheme.class.getProtectionDomain().getCodeSource().getLocation().getFile();

jarFilePath = java.net.URLDecoder.decode(jarFilePath, "UTF-8");

System.out.println("+++++++++++++++++++++++++++++++"+jarFilePath);

Scheme sch = new Scheme("https", 443, sf);

3、WAS输出:放到WAS上运行输出。

在Tomcat下,控制台输出为

/D:/Workspaces/MyEclipse Blue Edition 10/Binding/WebRoot/WEB-INF/lib/httpclient-4.3.3.jar

找到在WAS上该类解析的日志输出

/wasHome/IBM/WebSphere/AppServer/plugins/com.ibm.ws.prereq.jaxrs.jar

4、方法2

package test;

import java.io.IOException;
import java.io.PrintWriter;
import java.security.CodeSource;
import java.security.ProtectionDomain;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.httpclient.Cookie;
import org.apache.http.HttpResponse;
import org.apache.http.impl.client.DefaultHttpClient;

public class TestServlet extends HttpServlet {

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
ProtectionDomain pd1 = DefaultHttpClient.class.getProtectionDomain();
CodeSource cs1 = pd1.getCodeSource();

ProtectionDomain pd2 = HttpResponse.class.getProtectionDomain();
CodeSource cs2 = pd2.getCodeSource();

ProtectionDomain pd3 = Cookie.class.getProtectionDomain();
CodeSource cs3 = pd3.getCodeSource();
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println("  <BODY>");
out.print("   DefaultHttpClient类 导入为httpclient包,运行时JAR包是 >>>>>> ");
out.print(cs1.getLocation());
out.print("<br/>");
out.print("   HttpResponse类 导入为httpcore 包 引用的 JAR包是>>>>>> ");
out.print(cs2.getLocation());
out.print("<br/>");

out.print("   Cookie类 导入为commons-httpclient 包 引用的 JAR包是>>>>>> ");
out.print(cs3.getLocation());
out.print("<br/>");

out.println("  </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐