如何在 java 5 环境中使用 java 6 功能

发布于 2024-10-09 21:53:26 字数 275 浏览 0 评论 0原文

我面临一个奇怪的问题。我在 java 6 中开发了 java web 应用程序,当我将它托管在服务器上时,它显示错误,因为它的 java 5 服务器。我在代码中使用了注释、hibernate、rest API,现在我想用 java 5 环境转换我的代码。

可以这样做吗?如果是的话怎么办?或者有其他解决方法可以解决这个问题吗?请告诉我。

@all:这是我收到的错误:

alt text

I am facing an strange issue. I developed java web app in java 6 and when I hosted it on server, its shows error since its java 5 server. I have used annotations, hibernate, rest API in my code and now I want to transform my code with java 5 environment.

is it possible to do so? if yes HOW? Or is there any other workaround for this problem? Please let me know.

@all: This is the error i am getting:

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浮生未歇 2024-10-16 21:53:26

我不确定你的构建过程是什么,但你需要为特定目标(如 java 1.5)编译代码。

  • 如果您从命令行使用 javac,请查看 -target 开关
  • 如果您使用 ant,则查看 target 属性。

如果您使用 java 1.6 特定的库,您将会遇到问题。当您尝试运行代码/网络应用程序时,您就会知道这一点。

我希望这有帮助。

I am not sure what your build process is but you need to compile your code for a specific target like java 1.5.

  • If you are using javac from the command line look at the -target switch
  • If you are using ant then look at the target property.

You will run into problems if you are using java 1.6 specific libraries. You will know this when you try and run your code/webapp.

I hope this helps.

不及他 2024-10-16 21:53:26

您必须查看各个错误并找出缺少的内容。

JPA 注释已经是 Java EE 5 的一部分,因此如果“hibernate”导致问题,则意味着您实际上并未在 Java EE 5 上运行,或者您正在使用特定于 hibernate 的注释。 REST 注释确实是在 Java EE 6 中添加的,但通过将带有 API 的 JAR 以及实现(例如 Apache Jersey)添加到应用程序的类路径,可以相对轻松地在 Java EE 5 环境中使用 REST 注释。

顺便说一句,关于 Java SE 与 Java EE 存在一些混淆。您显然在谈论 Java EE 功能,但 Java SE(大多数人在提到“Java”时都会想到)和 Java EE 之间存在很大差异。

You'll have to look at the individual errors and figure out what is missing.

The JPA annotations were already part of Java EE 5, so if "hibernate" is causing problems, it either means you are not in fact running on Java EE 5, or you're using hibernate-specific annotations. The REST annotations were indeed added in Java EE 6, but can be used in a Java EE 5 environment relatively easily by adding a JAR with the API as well as the implementation (e.g. Apache Jersey) to the app's class path.

BTW, there's some confusion here concerning Java SE vs. Java EE. You're clearly talking about Java EE features, but there is a big difference between Java SE (which most people think about when you just say "Java") and Java EE.

无声情话 2024-10-16 21:53:26

从您的帖子来看,您似乎正在 Java EE 5 环境中使用 Java EE 6 功能。如果你的应用程序。服务器在其核心级别不支持此类功能,例如在 Servlet 2.5 环境中使用 Servlet 3.0 功能,那么您就不走运了。

但是,当使用像 Hibernate 这样的库功能时,您可以在 Java EE 5 环境中使用它。

Java 6 作为一种语言与 Java 5 保持不变,但库已发生变化。同样,使用 6 中的 JRE 类和方法在 5 中不起作用。

更新:从您的屏幕截图中,我看到您在旧版本的 Tomcat 上使用 Java 6 编译的类。针对 Java 5 编译它们。

From your post, it seems you're using Java EE 6 features in a Java EE 5 environment. If your app. server doesn't support such features at its core level, such as sing Servlet 3.0 features in a Servlet 2.5 environment, then you're out of luck.

However, when using features that are libraries, like Hibernate, you can get away using it in a Java EE 5 environment.

Java 6 as a language remains the same as Java 5, however, libraries have changed. Likewise, using JRE classes and methods that are in 6, won't work in 5.

Update: from your screenshot, I see that you're using Java 6 compiled classes on an older version of Tomcat. Compile them for Java 5.

眼中杀气 2024-10-16 21:53:26

您正在尝试在 Java 5 上运行针对 Java 6 编译的类(Tomcat 5.x 使用 Java 5)。

  1. 您可以升级到 Java 6。
  2. 您可以通过使用 javac 的“-target”参数将类编译为与 Java 5 兼容,但此选项不会有帮助,因为问题出在 servlet api 上。 JEE6 需要 Java 6。

You are trying to run classes compiled against Java 6 on Java 5 (Tomcat 5.x uses Java 5).

  1. You can upgrade to Java 6.
  2. You can compile the classes to be Java 5 compatible by using "-target" argument to javac but this option is not going to help as the problem is occuring with the servlet api. JEE6 requires Java 6.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文