Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why can't I run these jar files on a PC that doesn't have the JRE 6?

 
Clark Johnson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me be more explicit. It appears that it is not possible to run a jar file containing .class files compiled using the JDK 6 on computers that only have the JRE 5. I tried to run some jar files on some computers that only had the JRE 5 installed, but I kept getting a message saying that the main class was not found (the manifest files are fine). When I tried to run the jar files on computers that had the JDK 6 installed, the programs worked fine.

I don't want every person who will be using this program to have to download the latest JRE. Will I solve this problem if I compile the files using the JDK 5.0?
 
Campbell Ritchie
Sheriff
Posts: 48441
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know:- Yes.

As long as you only use JDK5 compatible features.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use JDK 6 to create class/jar files for use with JDK 5. Check out the "-source" and "-target" options of javac.
 
Clark Johnson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,
After researching this subject, I'd like to mention that compiling Java 5-compatible programs, using the JDK 6, using the -source and -target parameters, won't always work, as these parameters won't detect references to classes that were introduced in subsequent Java versions.

I suggest that anyone trying to take care of a similar problem compile his or her programs using the JDK 5 instead.
[ March 22, 2007: Message edited by: Clark Johnson ]
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Clark Johnson:
... as these parameters won't detect references to classes that were introduced in subsequent Java versions.

I'm not sure what you mean by this. All those settings are doing is making sure that the class files produced can be run on an earlier JVM. If the code contains JDK6-only methods, then you need to make sure that they are not executed on a Java 5 JVM (by including appropriate checks in the code).

Obviously, JDK 5 will not be able to compile code that uses any JDK 6 methods, so the workaround of using JDK 5 to compile the program is not really going to work.
 
Clark Johnson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Obviously, JDK 5 will not be able to compile code that uses any JDK 6 methods, so the workaround of using JDK 5 to compile the program is not really going to work.[/QB]


Correct, but depending on the size of your program, it can easier to have the JDK 5 tell you which methods won't work than rereading the documentation of all the methods you used. It seems like a safer and more efficient way to take of this problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic