Websphere Classes冲突诊断

作者:tacy lee

由于大量开源框架的采用,Classes冲突的问题在我们的项目中越来越常见,下面写了一个简单的jsp,用来查找当前使用类的位置:

<%@page contentType="text/html; charset=gb2312" %>

<html>
  <head>
    <title>Class conflict</title>
  </head>
  
  <body>
      Example input: com.primeton.tp.web.driver.webdriver.PageDriver<br>
    <form action="<%=request.getRequestURI()%> " method="post">
      <input type="text" name="className" size="50" ><br>
      <input type="submit" value="submit">
    </form>
    <%
            String classLocation = null;
            String className =request.getParameter("className");

            if ((className != null) && ((className = className.trim()).length() != 0)) {
              try{
                classLocation = Class.forName(className).getProtectionDomain().getCodeSource().toString();
                }catch(Throwable e){
                    log("error=" + e, e);
                }

                if (classLocation != null) {
                    out.println("Class " + className + " found in <br>" + classLocation );
                }
              else {
                  out.println("Class '" + className + "' not found" );
                }
            }
    %>
  </body>
<html>

 

通过这个jsp页面可以输入需要查询的类

-----------------------------------------------------------------------------------------------------------------------------------------------------

另外,websphere可以通过下面两个方法来改变类的加载:

1、在"Applications" >"Enterprise Applications" >" yourear ">" Class Loading and File Update Detection"

修改:"Class loader mode" 为 "Parent Last",这样应用类可以覆盖父装载器的类

当然但如果你混合使用了被覆盖的类和没有被覆盖的类,则此操作有可能会导致 ClassCastException 或 LinkageErrors

2、在"Servers" > "Application servers" > "yourserver" > "Process Definition" > "Java Virtual Machine"

添加CLASSPATH,让你的类先加载

posted on 2007-12-21 18:05 tacy lee 阅读(1320) 评论(0)  编辑  收藏 所属分类: 测试相关


只有注册用户登录后才能发表评论。


网站导航: