aspose file tools*
The moose likes Features new in Java 7 and the fly likes Jar file created using  JVM 7  do not work  on machines  having  JVM6 or lower versions. Is it true? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "Jar file created using  JVM 7  do not work  on machines  having  JVM6 or lower versions. Is it true?" Watch "Jar file created using  JVM 7  do not work  on machines  having  JVM6 or lower versions. Is it true?" New topic
Author

Jar file created using JVM 7 do not work on machines having JVM6 or lower versions. Is it true?

Vijay Tyagi
Ranch Hand

Joined: Feb 15, 2010
Posts: 52
Jar files created using JVM 7 are not working on machines having JVM6 or lower versions for me
It was running fine
I uninstalled JRE7 ,JDK7 and all other JREs and JDKs. And then installed JRE6.I got the error "could not find main class: ABC"
On installing JRE7 again it's working.
Is there a way to make jar files created using JVM7 run on lower versions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

The simple answer is: no.

Newer Java versions are compatible with older versions, so anything that has been compiled on JDK 6 or older will work on Java 7 (except for some minor issues).

But code compiled with a newer version will not work on an older version.

If you need your code to work on Java 6, then it's best to use JDK 6.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

This will give UnsupportedClassVersionError unsupported major.minor version error, i believe. You should compile your code with the same version on which you want to run. If you are using eclipse you can change the compile level.
Vijay Tyagi
Ranch Hand

Joined: Feb 15, 2010
Posts: 52


Suppose a jar file is created using Java 7 update7 ,will it work on a computer having JRE 7 update 5 ?

thanks
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

Yes, that will work. Update releases are only to fix bugs and other problems, no major new functionality is added in update releases.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

Jesper de Jong wrote:But code compiled with a newer version will not work on an older version.

Unless you tell the compiler to make the generated byte code compatible with an older version (-source and -target compiler flags).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Rob Spoor wrote:
Jesper de Jong wrote:But code compiled with a newer version will not work on an older version.

Unless you tell the compiler to make the generated byte code compatible with an older version (-source and -target compiler flags).

Additionally, your code needs to not depend on any newer library methods or classes. If a method was added in JDK 7, it won't be available using the older library, and your code will fail when it tries to call that method. This can be a little harder to check for - I find if I really need something to run on JDK 6, it's best to compile and test using JDK 6, not relying on the -source and -target options. But it is possible to get it to work using the -source and -target, if you need to. It's just risky.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
You should be able to tell which methods are available in Java6, because there should be a “since” tag in the documentation, as here (since 1.4).


Of course, they might have forgotten to write a since tag …
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Sure - if you check every method in the codebase. But that's kind of tedious and error-prone for a large codebase. And I don't know of an automated tool that does it, though it's theoretically possible. Anyone?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jar file created using JVM 7 do not work on machines having JVM6 or lower versions. Is it true?