与蚂蚁/詹金斯类转换异常产生的EAR到WebSphere 6.1 [英] Class cast exceptions with ant/jenkins generated EAR on WebSphere 6.1

查看:299
本文介绍了与蚂蚁/詹金斯类转换异常产生的EAR到WebSphere 6.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我部署作为詹金斯运行到WebSphere 6.1 Ant构建脚本的一部分生成耳后,其运行时类转换异常。演员类的例外是在投对象从SQL查询到特定的类返回一些DAO方法。

I'm having runtime class cast exceptions after deploying an ear generated as part of an ant build script running on Jenkins to Websphere 6.1. The cast class exceptions are in some DAO methods which cast Objects returned from SQL queries to specific classes.

如果我生成的Eclipse(RAD)内的EAR那么类转换异常不会发生,并且类文件从Eclipse中的那些詹金斯/蚂蚁耳朵产生比较显示不同的文件大小和内容。

If i generate the EAR from within Eclipse (RAD) then the class cast exceptions don't occur, and comparing the class files from the jenkins/ant generated ear with the ones from Eclipse show different file sizes and contents.

我试图让蚂蚁执行的javac与Webspehre 6.1提供的JDK。所以我成立了詹金斯多配置项目使用IBM JDK。我猜想,这使蚂蚁javac任务使用JDK。

I'm trying to make ant execute javac with the JDK supplied with Webspehre 6.1. so I've set up a multi configuration project in Jenkins to use the IBM JDK. I'm assuming that this make the ant javac task use this jdk.

这是我的蚂蚁javac任务:

This is my ant javac task:

    <javac srcdir="${src.dir}" destdir="${build.dir}"  debug="true"  debuglevel="vars,lines,source" target="1.5">
        <classpath refid="master-classpath" />
    </javac>

我现在能想到的唯一的一点是要确保蚂蚁实际上这个JDK运​​行,而不是仅仅执行javac的这个JDK。有没有一种方法来检查?

The only thing I can think of now is to make sure that ant actually runs with this jdk as opposed to just executing javac with this jdk. Is there a way to check?

我已经改变了ant.bat文件输出JAVA_HOME,它并同我在詹金斯指定下运行。

[edit] I 've changed the ant.bat file to output JAVA_HOME and it does run under the one I specify in jenkins.

好吧,终于找到了问题的原因:

Ok, finally found the cause of the problem:

在Hibernate的DAO方法,我们有一些(差)code是这样的:

In a Hibernate DAO method we have some (poor) code like this:

String sql = "select {entity.*}, {entity2.*}, ...";
SQLQuery  query = sessionFactory.getCurrentSession().createSQLQuery(sql);
...
List<Entity> queryResult = query.list();
for (Object row : queryResult) {
     Object[] arr = (Object[])row;
     Entity entity - (Entity)arr[0];
     Entity2 entity2 - (Entity2)arr[1];
}

您可以发现男生的错误?

Can you spot the schoolboy error?

QueryResult中不是列表&LT;实体&GT; 列表&LT;对象[] &GT; - 类转换异常是存在的关于的(对象行:QueryResult中)

queryResult is not a List<Entity> but a List<Object[]> - the class cast exception was occuring on for (Object row : queryResult)

所以,现在我的问题是 - 什么事键入删除

So, now my question is - what happened to type erasure?

和什么编译器使用Eclipse,允许它忽略选项,在运行时,类蒙上这样的错误?

And what compiler option is Eclipse using that allows it to ignore, at runtime, class casts errors like this?

推荐答案

这是可能它不是JDK,但其他的库,供不同。值得一试。

It's possible it's not the JDK, but other libraries which are different. Worth checking.

这篇关于与蚂蚁/詹金斯类转换异常产生的EAR到WebSphere 6.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆