File reading using OpenCSV - java

I use OpenCSV for CSV files reading and writing. It worked fine until I hsd to install earlier version of Java - i.e. Java 6. After installing it, my code stopped working:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/opencsv/CSVReader : Unsupported major.minor version 51.0 at
java.lang.ClassLoader.defineClass1(Native Method) at
java.lang.ClassLoader.defineClassCond(Unknown Source) at
java.lang.ClassLoader.defineClass(Unknown Source) at
java.security.SecureClassLoader.defineClass(Unknown Source)

Check the version of the class file in your OpenCSV .jar dependency, for example:
javap -verbose -cp opencsv.jar com.opencsv.CSVReader | grep major
If this shows a version newer than 50 (= newer than Java 6) then you cannot use this jar.
You need to get a .jar file built with Java 6 or older. (If it can be built with Java 6 at all.)
I just confirmed that the latest version of the source code doesn't compile with Java 6,
as it uses Java 7 features (naturally).
But not too long ago, as of August 2014 the project was still on Java 5.
So if you download an older version of the jar it should work.
In other words, since you downgraded your Java version,
you also need to downgrade your OpenCSV dependency.
UPDATE
From SourceForge, version 2.3 contains a jar file that should be suitable for you:
$ javap -verbose -cp deploy/opencsv-2.3.jar au.com.bytecode.opencsv.CSVReader | grep major
major version: 50
Note that the package name is a bit different from the current version.

When OpenCSV was upgraded to 3.0 the decision was made to upgrade to Java 7. This was done for several reasons. The main reason being that the largest reason was that the main fixes in 3.0 was to support the lazy checks in Lambdas that are in Grails (possibly Java 8) so it was requested the code be compiled in Java 7 because it is more optimal for Grails. I allowed that because Oracle had announced it was dropping support for Java 7 in 2015 and Java 5 & 6 had long since been unsupported plus I had a small number of emails asking when I was going to port opencsv to java 7 (and only one for java 8 for some reason) so I felt that moving to java 7 was safe. The last was that I develop using a mac and no longer have access to a java 5 compiler and I really did not feel good about pushing out a Java 5 version of opencsv built using java 7.
In hindsight seeing the issues that this caused (you are the third that I know of that cannot upgrade because of this) I would have left it at Java 5 and asked the Grails users to perform a performance test and myself build opencsv in a Ubuntu VM on my mac. But since it is out I don't want to downgrade and possibly effect users as well.
If you cannot upgrade your project to java 7 you do have two options: the first is that on the sourceforge and maven repositories you can download the older versions. So 2.4 and earlier was built using java 5. The other option is that you can download the code and build it yourself. Thanks to KommradHomer the current code base is compatible with Java 6 and will build as is with a Java 6 compiler (you just need to change the pom file).

I am seeing the same issue. Please let me know which version of openCSV I can use to be compatible with java version "1.6.0_22" ? OpenCSV 2.3 does not work for me.

Related

UnsupportedClassVersionError problem on Apache Ignite using Java 7 with Ignite jars

I am using Apache Ignite server in my application with Ignite jars (Ignite jar version 2.12.0) alone and I did not implemented with the Ignite standalone software, since it requires separate software.
The problem is that, when used with Java 8, it is running properly, when used with Java 7, it is showing UnsupportedClassVersionError.
Note: In my application the requirement is Java 7 only.
Error details:
java.lang.UnsupportedClassVersionError: org/apache/ignite/spi/discovery/tcp/ipfinder/TcpDiscoveryIpFinder : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
Could any one guide on that? How to use Apache Ignite with Java 7?
I concur with #Mark Rotteveel. Java 7 is long past its end-of-life, and continuing to develop new code for that platform is a mugs game1, 2.
Upgrade to Java 8. Tell the boss it needs to be done.
However, assuming that you want to keep digging yourself deeper into the Java 7 hole ...
Looking at the Apache Ignite release history, I see that Java 7 support was dropped in Ignite 2.4. So if you were willing and able to roll back to Ignite 2.3 or earlier, there is a good chance you can put off upgrading to Java 8 a bit longer.
Another alternative would be to checkout more a more recent version of Ignite from the official source repository, and see if you can build it for Java 7. (The Java source and target versions are set in the "parent/pom.xml" file ...)
Q: Which post 2.4 version(s) of Ignite will still build for Java 7?
A: I don't know. You may have to modify the code to make it build, especially if they have started using new Java 8+ language features.
Q: Will the built code work?
A: I don't know.
Q: Will the back-ported code be supported by the code authors?
A: Not a chance!
1 - ... unless you or your company are being very well paid for doing this work. In that case, the mugs are your clients.
2 - https://www.merriam-webster.com/dictionary/a%20mug%27s%20game
The minimum supported version is Java 8. I don't think you'll get it working on anything older. Java 7 was released in 2011 and has not been supported for some time.

Launch4j-FakeMain compiled by more recent version Java Runtime(class file version 55 0)this Java Runtime only recognizes class file version up to 52 0

This is my first application that i try to execute exe.
I'm using launch4j to do this. After executing and trying to run, I get this error:
Blockquote
Launch4j - Exception in thread "main" java.lang.UnsupportedClassVersionError: FakeMain has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
I searched something about versions of java, so I checked my versions of java and they are the same.
That's my versions of java:
My versions of java in cmd
Maybe I did something wrong there?
Screen of Launch4j
I don't know what I can do. I spend all this day about fix this and nothing.
Error after try to run exe file
You have compiled the code with Java 11 as target. But your PC want's to execute the Java Code with Version 8, which is not possible.
Make sure you have installed the correct Versions and also make sure that the executable uses Java 11.
Here you can find the Java Versions mapped to the Runtime Versions: Java Version Numbers
The Article gives you also some information about how to compile and execute for the correct versions.

Unsure if I am using the correct version of Java for Eclipse

I am having a bit of trouble determining if I am running the correct version of Eclipse and/or Java. I am attempting to make changes to a JAXB program for work. I can't run the program and an error is generated that states
java.lang.UnsupportedClassVersionError: RunISOPaymentFileSimulator : Unsupported major.minor version 51.0
I know from doing my research using the search function this means that I need version J2SE 7.
After searching for my current version I find that I have Java 6 Standard Edition build 1.6.0.
My question is this: Is Java 6 the same thing as J2SE 6? Do I need to just update my Java version to 7 or do I need to also find the special J2SE 7?
Thanks very much!
Neither Java not J2SE is specific enough. What you need is the Java 7 JRE (Java Runtime Environment.) You probably already have it but your JAVA_HOME is set to 6. Changing your JAVA_HOME can cause issues for some applications that are written poorly so be prepared to have to switch it back.
http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html

How do we decide which java version is used to compile a version of library in maven?

My local setup has all java 6 configured. I needed catalina jar file. So I took the latest one -
http://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina/8.0.15
but that gave me following errors/warnings
warning: javalangObject.class(javalang:Object.class): major version 51 is newer than 50, the highest major version supported by this compiler.
and build failed.
Only way this was possible is that catalina.jar is compiled with java 7 and my setup is using java6. I confirmed that was the case by using an older version of the library.
http://mvnrepository.com/artifact/org.apache.tomcat/catalina/6.0.35
I would like to know how do we know which library version is compiled with which version of java. Specifically in Maven I don't see any such information.
Major version of 51 means it was compiled with Java 7. Major version 52 means, it was compiled with Java 8. Java 6 has major version 50.
You may extract some class files out of the jar downloaded from Maven. Then check the major version of the class as below:
$ javap -verbose someclass.class | grep -i major
Which will indicate the javac version used for compiling.

Java .jar not running in unix

I've created a executable jar file in an Windows environment. I'm able to run this jar without any problems in Windows.
When I try and run the same jar in a unix environment, I get the following exceptions:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
What am I doing wrong?
You are trying to run it under an earlier version of Java.
You can compile targeting the correct version, or run under a newer version.
Looks like you're building on Java 7 and then trying to run on Java 5, or something like that. It's not a matter of Windows vs Unix - it's a matter of the version of Java within the operating system.
Ideally, upgrade your Unix system to a recent release of Java - or if you can't do that, change how you're building to use the -target flag in javac to generate appropriate bytecode. You should target the right version of the standard libraries for the environment you need to run in, too.
You are trying to run a program compiled on a newer version of Java on an older version of Java.
Make sure the program is compiled for the appropriate target version that you will be running on. You can set compile options to use a newer compiler to create programs that will run on older versions, but obviously you can't use newer features.
For example: Java 7 runs all previous versions of binaries. Java 5 can't run newer versions of binaries.
Make sure you have on both platforms the latest version of Oracle Java installed.
UnsupportedClassVersionError means that you compiled the class with a version of Java that is newer than the version of Java that you are trying to run the program on.
For example, you have compiled this with JDK 6, and you are trying to run the program on a Java 5 or older JVM.
That doesn't work. Newer versions of Java are able to run programs compiled with older versions, but not the other way around.
It's likely that you have an older version of Java on your *nix install as opposed to your Windows install. The jar was built using a newer version, meaning it can't run on the old version because it may have features that aren't supported yet. Try updating your *nix Java and try running it again.
It looks like the .class file was compiled with a newer version of java then your linux installation. please update the results of:
java --version
on both linux and windows, and check if you have java, and not openjdk, on linux (openjdk might bug).
if the version on linux is lower then on windows, that is the problem, update it.
Most likely you are trying to execute a jar file compiled with a compiler with a newer version than the JVM installed on the system where you are trying to execute it. Check JVM version on the Linux system and make sure to have a version equal or newer than the version of the compiler ...
(Posted on behalf of the question author).
Thanks for the help, it seems you all are correct. I developed the jar on java 1.6 and our unix server is on 1.5.

Categories