Reputation: 13864
I'm modifying a java program which was written in 2004 using javaw.exe from J2re1.4.2_03.
problem: Is there a way to figure out which JDK compiler a programmer used to compile a java file with?
backstory: I recompiled the java file with jdk5's javac. I run it with the javaw.exe from the j2re1.4.2_03, it gives me a popup error "Could not find the main class. Program will exit."
From some googling, error message means classes compiled with an even older javac.exe If I run it with a jdk5's javaw.exe, no error.
I want to avoid recompiling all the class files as I do not have all of the original java files to do a complete recompilation.
Is there a way around this or a way to figure out which compiler the original programmer used to do this? or one which works better with
thanks in advance
Upvotes: 0
Views: 293
Reputation: 719596
The simple answer is "No". According to the JVM specification, the only version information in a class file are the class format major and minor version numbers. These tell you the target JVM version, not the Java compiler version. (It is theoretically possible that there is Java compiler version information in some undocumented "attribute" in the class file, but if the javap
command doesn't show it, I don't know how you'd find it.)
As @manuel points out, if your class is in a JAR file, the JAR file manifest may contain version information. However, this will be version information for the jar
command used to create the JAR file, and there is no guarantee that the Java compiler used to compile had the same version. (Or even that a Sun compiler was used!)
However, I agree with others who said that this is probably NOT the root cause of your problem,
Upvotes: 0
Reputation: 926
Why don't you download jdk 1.4 and compile the file with it? Multiple jdk versions can coexist on any pc or server, just make sure to run the correct javac.
Upvotes: 0
Reputation: 16468
regarding your meta information question: sometimes you get some environment information, when you unpack the jar and have a look at /META-INF/MANIFEST.MF file.
Upvotes: 0
Reputation: 346526
From some googling, error message means classes compiled with an even older javac.exe
I'm pretty sure that's not it. Class files compiled with older compilers run just fine under a new JVM, and I've never encountered problems with mixing class files from different compilers either; the class file format is specified quite tightly.
I suspect the only thing you need to do is compile your new code with the -target 1.4
option (or use the 1.4 compiler) so that you're producing class files that the 1.4 JVM can understand.
Alternatively, just run the program with the 1.5 JVM - most likely it will work without problems.
Upvotes: 1
Reputation: 89849
I'm not so clear what your exact question is.
If you're wondering how the find out what version of Java a classfile is from, the header of a class file can be read. You can see the info here, and there are tools around that will inspect the files for you.
You should generally avoid using class files compiled by different compilers together. There are some ways around it, but you'll be in classpath hell. Are the new Java file compatible with the older versions (e.g., no generics?). You can always get the older compilers from Sun and just compile your newer files with this compiler.
Upvotes: 1