This is an old revision of the document!
Table of Contents
Java Tips
This page is a none-organized list of tips, mostly for the errors I encountered with Java programming and the trouble shooting.
Unsupported major.minor version 51.0
During compilation of Java program, I encountered this error message. The reason was pretty straight forward: when the program that is being compiled is referring to a library or jar file that was compiled using different JRE version, this message appears.
To overcome this error, simple re-compile all the jar files by a consistent JAVA version.
java.lang.SecurityException – signer information does not match signer information of other classes in the same package
I encountered this message when there is a conflict by having two same jar files in the class path. Removing one of them should over come this error. There seems to be more to it as an explanation, and for that refer to this page or the quote below.
This happens when classes belonging to the same package are loaded from different JAR files, and those JAR files have signatures signed with different certificates - or, perhaps more often, at least one is signed and one or more others are not (which includes classes loaded from directories since those AFAIK cannot be signed).
So either make sure all JARs (or at least those which contain classes from the same packages) are signed using the same certificate, or remove the signatures from the manifest of JAR files with overlapping packages.
Extract compiler version from a class file
Sometimes you want to know the version of Java compiler used for a certain class. Then do the following.
javap -verbose MyClass
There will be then a line “major version XX” at the beginning of the output. Below is the list of correspondence between Java version and “major version”.
It might be better to add head command since the version number appears at the beginning.
javap -verbose MyClass | head
Java 1.2 uses major version 46
Java 1.3 uses major version 47
Java 1.4 uses major version 48
Java 5 uses major version 49
Java 6 uses major version 50
Java 7 uses major version 51
JAR file
For directly accessing a jar file and get build environment for that jar file, following is an example jython code.
from java.util.jar import JarFile #from java.util.jar import Manifest def printClasses(jf): for e in jf.entries(): print e.getName() def printManifest(jf): mf = jf.getManifest() if mf is not None: mainatt = mf.getMainAttributes() keys = mainatt.keySet() for i in keys: print i, mainatt.getValue(i) else: print 'pity, No Manifest File found!' # main filepath = 'D:\\gitrepo\\CorrectBleach\\CorrectBleach_.jar' filepath = 'C:\\ImageJ2\\plugins\\CLI_.jar' filepath = 'C:\\ImageJ2\\plugins\\AutoThresholdAdjuster3D_.jar' jf = JarFile(filepath) printManifest(jf)
Currently Running Java
To know the version properties of currently running Java, see the following jython example:
>>>> print System.getProperty('java.runtime.version') 1.6.0_20-b02 >>>> print System.getProperty('java.vm.version') 16.3-b01