I have a small application written in Java that was tested and ran on a JRE_1.6. Now I need to run it against a JRE_1.5. I altered the source code I had to match Java 1.5 requirements and the project compiled fine.

The problem is that it uses a number of precompiled libraries like opencsv-2.3 and those were compiled with Java 1.6, so calling any of their classes results in a java.lang.UnsupportedClassVersionError.
Most of them are com.apache libs + opencsv-2.3 + org.jdom

How can I figure out which libraries exactly need to be replaced? How can I replace the libraries that need it?

Upd: the how can I replace part actually stands for "what can be done if there is no older library?" Is there a way to downgrade a compiled library or do I need to find a similar solution on 1.5 and rewrite the code?

有帮助吗?

解决方案

I suggest you look in the manifest for each library for lines like

Bundle-RequiredExecutionEnvironment: J2SE-1.3
X-Compile-Target-JDK: 1.5
Build-Jdk: 1.5.0_22
Created-By: 1.6.0_21-b07 (Sun Microsystems Inc.)

I would only take the create by if no other option appears.

The only way to know for sure is to example a class in the library (assuming all classes where built for the same version)

javap -v -classpath net\sf\trove4j\trove4j\3.0.2\trove4j-3.0.2.jar gnu/trove/list/TLongList | grep version

  minor version: 0
  major version: 49

A table of versions are

major  minor Java platform version 
45       3           1.0
45       3           1.1
46       0           1.2
47       0           1.3
48       0           1.4
49       0           1.5
50       0           1.6
51       0           1.7
52       0           1.8

For more details http://en.wikipedia.org/wiki/Java_class_file

其他提示

As @Peter Lawrey, for example opencvs:

opencvs-2.2

manifest file (MANIFEST.MF) is in folder META-INF inside the jar.

I had the same problem, and I just rebuilt the source files in open-csv with JDK 1.5 - problem solved!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top