How to use java 6 features in a java 5 environment

China☆狼群 提交于 2019-12-11 04:45:39

问题


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:


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.


来源:https://stackoverflow.com/questions/4537673/how-to-use-java-6-features-in-a-java-5-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!