使用 ant/jenkins 在 WebSphere 6.1 上生成 EAR 的类转换异常 [英] Class cast exceptions with ant/jenkins generated EAR on WebSphere 6.1

查看:24
本文介绍了使用 ant/jenkins 在 WebSphere 6.1 上生成 EAR 的类转换异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将作为在 Jenkins 上运行的 ant 构建脚本的一部分生成的耳朵部署到 Websphere 6.1 后,我遇到了运行时类转换异常.转换类异常存在于一些 DAO 方法中,这些方法将从 SQL 查询返回的对象转换为特定类.

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,则不会发生类转换异常,并且将 jenkins/ant 生成的 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.

我正在尝试使用 Webspehre 6.1 提供的 JDK 使 ant 执行 javac.所以我在 Jenkins 中设置了一个多配置项目来使用 IBM JDK.我假设这使 ant 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>

我现在唯一能想到的就是确保 ant 确实用这个 jdk 运行,而不是仅仅用这个 jdk 执行 javac.有办法查吗?

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,它确实在我在 jenkins 中指定的文件下运行.

[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 方法中,我们有一些(糟糕的)代码,如下所示:

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 不是 List 而是 List - 类转换异常发生在 <代码>for(对象行: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.

这篇关于使用 ant/jenkins 在 WebSphere 6.1 上生成 EAR 的类转换异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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