File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Getting jar to run on old java version Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting jar to run on old java version" Watch "Getting jar to run on old java version" New topic
Author

Getting jar to run on old java version

Robert Lippens
Greenhorn

Joined: Jun 23, 2013
Posts: 27
Hi guys,

I am trying to send my friend a program I made in Java.

His computer runs java version 1.5.0_30 using the Java(TM) 2 Runtime Environment. So, in my Eclipse project, I went to properties, and then java compiler, where I changed the default compliance to J2SE-1.5, as well as changing my system library in the build path to JRE System Library [J2SE-1.5]. I thought this would make the program run on his system but when he attempts to run my program he gets the error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file

The rest of the error messages do not relate to any of my class files, and the stacktrace just links back to java.net and sun.misc files.

Going back to the project properties, it tells me that every execution environment I can select requires Java SE 6. My friend runs Java SE 5 on a 32 bit architecture Intel mac and cannot update to SE 6(for some reason Apple found it prudent to not support an up-to-date version of Java for 32 bit intel architectures.) My computer is a 64 bit architecture (Intel Mac) and I can't seem to get SE 5 on it.


My other friends have no problem opening the jar, so I know it is functioning properly. I was wondering if there was any way I could get it to run on his older system? I've been beating my head against this for an hour now with no success.

Thanks!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42639
    
  65
32bit vs. 64bit should not make a difference. I think it's more likely that the settings in Eclipse were not quite what was needed. I don't know Eclipse, so I can't advise on that, but Java in general has two sorts of compatibility: source file compatibility and class file compatibility. On the command line, those would be set via the -source and -target switches, respectively. Maybe the Eclipse docs talk about that in more detail.


Ping & DNS - my free Android networking tools app
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8248
    
  23

Robert Lippens wrote:His computer runs java version 1.5.0_30 using the Java(TM) 2 Runtime Environment.

I guess my question is: Why?

Java 1.5 has been obsolete for more than 5 years now (nearly 7, if you mark the time from the release of 1.6), and public updates were stopped at the end of 2009. If your friend is smart enough to run a Java app, surely he can manage an upgrade?

Obviously, some measure of backward-compatibility is needed, but I think you're stretching the limits by trying to cater for people who are two full releases (soon to be 3) out of date. You are also hamstringing yourself, because you won't be able to use new features.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42639
    
  65
Winston Gutkowski wrote:surely he can manage an upgrade?

Not if the OS version is too old - that's how I understand the post. The last OS X version not to support Java 6 was 10.4, though (see table 4 here) - which is getting very long in the tooth, and (I think) doesn't receive security updates any more. So I would advise him to upgrade to a newer OS X version. It is unreasonable to expect to be able to run current software on such an old OS.
Robert Lippens
Greenhorn

Joined: Jun 23, 2013
Posts: 27
The issue is the architecture. Java SE 6 will only run on 64-bit architectures for Intel mac's and he has a 32-bit (found this out via his system specs/apple website). He could have the latest OS X version but, due to his architecture, would not be able to upgrade to SE 6.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42639
    
  65
Ah yes, that rings a bell. Some of the early Intel Macs were 32-bit only. Sorry, you did say that at the beginning.

But you should still be able to compile your code to run on Java 5 via the switches I mentioned (or their equivalents in Eclipse). That assumes that your code makes no use of any Java 6 features, of course. It also assumes that all libraries the code may use are compiled for Java 5 as well.

Which class was the error message about, specifically - one of yours? Or some library? Can you post the entire stack trace?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8248
    
  23

Robert Lippens wrote:The issue is the architecture...

I wasn't aware of those restrictions; although they sound like they're restricted to only Apple Mac users - which, in itself, seems surprising; I was under the impression that Apple had embraced Java (and Unix) pretty comprehensively.

All that aside: your friend is missing out - and you are being hamstrung - by a version that most of us (me included - and believe me, I'm Jurassic when it comes to change), discarded a long time ago.

If s/he is interested, I bought a 22-inch iMac desktop (bigger and nicer screen than anything else I own, and basically brand-new) for 450 Euros. Seems to me you could waste that much cash in man-hours just faffing about with "old versions".

My problem? I'm not ready for it. I'm an old (getting on for 30 years) Unix/Linux/Windows man, and I'm just not ready to "embrace Appledom". So it sits in my cupboard, waiting for the day that my old Dell decides to give up the ghost. When it does though? I'm ready...I'm an old Unix sysadmin, so AppleOS doesn't hold too many fears. I just don't need to make the change right now.

But 5 years out of date? I hope I curl up my tootsies or open a hotel for fly-fishing (unlikely) before I ever get that Jurassic.

Winston
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14351
    
  22

With a newer JDK, you can compile Java code to run on an older Java version; you'd have to use the -source and -target switches with the compiler:

javac -source 1.5 -target 1.5 MyProgram.java

But you'd still have to be careful not to use any classes from Java's standard library that were added in Java 6 or later, otherwise your friend will get a NoSuchMethodError or something similar when he runs the program.

If you're using Eclipse, there are project settings that you can change to make it Java 5-compatible (right-click the project, select Properties, and find the setting somewhere there).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting jar to run on old java version