Java - 由于 UnsupportedClassVersionError,Ant 构建和部署到 JBoss 失败
我正在尝试使用 Eclipse 中捆绑的 Maven-Ant 脚本构建项目并将其部署到 JBoss 部署文件夹,但最终 JBoss 总是记录以下内容:
nested throwable: (java.lang.UnsupportedClassVersionError: Bad version number in .class file)
该项目使用的软件如下:
- Ant 1.6.5
- Maven-Ant任务插件 2.1.3
- JBoss 4.0.5 GA
- JDK 1.4
在 Eclipse 中的 Window>Preferences 下,我将 JDK 添加到 Java>Installed JRE
也会列出并将其设置为默认值,以防万一。在 Project>Properties>Java Compiler
下,我已将合规性级别设置为 1.4,并且还尝试了其他合规性设置,但没有成功。
此外,JBoss 设置为使用完全相同的 JDK,即 Oracle 网站上的 1.4_03。奇怪的是 Eclipse 倾向于将其标识为版本 1.5。例如,在 Java 编译器页面上它说:
选择 1.4 合规性时,请确保安装并激活兼容的 JRE(当前为 1.5)。
有人可以给我一些建议吗?我哪里可能出错了?
提前致谢!
I am trying to build and deploy a project to the JBoss deploy folder with the bundeled Maven-Ant script from Eclipse but it always ends up with JBoss logging the following:
nested throwable: (java.lang.UnsupportedClassVersionError: Bad version number in .class file)
The used software for this project is following:
- Ant 1.6.5
- Maven-Ant Tasks plugin 2.1.3
- JBoss 4.0.5 GA
- JDK 1.4
In Eclipse under Window>Preferences I added the JDK to the Java>Installed JREs
list and set it to default too just in case. Under Project>Properties>Java Compiler
I have set the compliance level to 1.4 and have also played with the other compliance setting without any success.
Also, JBoss is set to use the exact same JDK which is 1.4_03 from the Oracle website. Odd is that Eclipse tends to identify it as version 1.5. For example on the Java Compiler page it says:
When selectiong 1.4 compliance, make sure to have a compatible JRE installed and activated (currently 1.5).
Can anybody give some advice where could I have gone wrong?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要确保 Ant 脚本也使用正确的版本;您收到 1.5 警告有点令人不安 —— 我发现很难相信 Eclipse 会错误地识别 JDK。另外,请记住,JDK 与 JRE 不同,因此请仔细检查您的路径/等。
您还需要确保您部署的所有库以及 JBoss 的库都是使用 1.4 编译的——如果您的项目有依赖项,那么它们的库很可能不是在 1.4 上编译的。
另外,说“J2EE JDK 1.4”有点令人困惑,因为 Java EE 和 Java SE 是两个不同的东西,据我所知,您无法在 JDK 1.4 下运行 J2EE 1.4。
You need to make sure the Ant script is also using the correct version; that you get the 1.5 warning is a little troubling--I find it difficult to believe that Eclipse would identify a JDK incorrectly. Also, bear in mind that a JDK is not the same as a JRE, so double-check your paths/etc.
You also need to make sure that all your deployed libraries, and those of JBoss, are compiled with 1.4--if your project has dependencies, it's likely their libraries are not compiled at 1.4.
Also, saying "J2EE JDK 1.4" is a little confusing, because Java EE and Java SE are two different things, and you wouldn't be able to run J2EE 1.4 under JDK 1.4, AFAIK.
结果我用的JDK版本不对。我联系了一位以前的开发人员,他说它绝对应该与 JDK 1.5 update 9 一起工作,这让一切变得不同。我已经克服了那个模棱两可的错误消息。抱歉,造成混乱,伙计们!
The JDK I used turned out to be the wrong version. I got in touch with one of the previous developers and he said it definitely should work with JDK 1.5 update 9 and that made all the difference. I got past that ambiguous error message. Sorry for the mess, guys!
这意味着 JBoss 中的某些类是用不兼容(更新的)版本编译的
Javac(具有更大的主编号),并且运行 JBoss 的 JRE 拒绝加载它。
(有问题的类位于 stacktrace 上的某个位置)
唯一的解决方案是使用更新的 JDK 来运行 JBoss 并编译(1.4 已经很旧了,据我所知不再支持)
This means that some class inside JBoss was compiled with incompatible (more recent) version
of Javac ( has bigger major number ) and your JRE runung JBoss refuses to load this.
( offending class is somewhere on stacktrace )
The only solution is to use more recent JDK to run JBoss and compile ( 1.4 is pretty old and AFAIK no longer supported )
我将开始查看您的 Maven/ant 环境属性。
Eclipse中的jdk选择仅在ide中使用。 java_home 和其他设置在您的 maven 属性或 ant 属性中的选项将用于编译和构建。
我还会检查您的 JAVA_HOME 环境变量,就好像它没有在属性文件中明确设置一样,它将从环境中获取。
I would start looking in your maven/ant environment properties.
The jdk selection in Eclipse is only used in the ide. The java_home and other options set int your maven properties or ant properties will be used for the compile and build.
I would also check your JAVA_HOME environment variable as if it isn't explicitly set in a properties file it will be acquired from the environment.