| Forums: |
java
vc
|
| Author |
JRE vs. JDK
|
Brian Winkler
Greenhorn
Joined: Jun 05, 2012
Posts: 16
|
|
Sorry if this is in the wrong section, but I am guessing it is a beginner mistake on my part.
I wrote a small app today in Eclipse that ran fine on my local machine (Mac Book Pro). I then sent it to a friend who is on CentOS and the app errored out for him. I told him he need to run Java7 as that was how it was developed, but it still would not run. I then installed that app on a Mac Mini of mine, and I was getting the same error. I went to Java.com and made sure to download and install the latest JRE and still got errors. On a whim, I downloaded and installed the JDK, and now the program runs fine. Is there a preference I need to select when creating a .jar or in my properties of the app itself that allows it to run in the JRE?
Just some additional information in case it is relevant, I used fatjar to make the jar file as I had some dependencies i needed to keep.
Thank you in advance for any help.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9955
|
|
It is easier to diagnose the problem if you tell us what the error was...the EXACT text.
There are potentially hundreds of reason why it could error, and without knowing what the error was, all we can do is guess.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Brian Winkler
Greenhorn
Joined: Jun 05, 2012
Posts: 16
|
|
Sorry, here you go, hope this helps.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Is this error when you run the app, or when you load Eclipse?
In case it is an Eclipse‑related question, I shall try (I have never done this before) duplicating the discussion in our IDEs forum, and maybe you will get more attention there.
|
 |
Brian Winkler
Greenhorn
Joined: Jun 05, 2012
Posts: 16
|
|
Campbell Ritchie wrote:Is this error when you run the app, or when you load Eclipse?
In case it is an Eclipse‑related question, I shall try (I have never done this before) duplicating the discussion in our IDEs forum, and maybe you will get more attention there.
The .jar is a plugin for a game. the error happens when the game starts. So I guess you would say when you run the app.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56221
|
|
|
That error almost always means that the class is trying to be executed in a JRE of an earlier version than the JDK that created it. Are the CentOS and Mac Mini running earlier version of Java than your Pro?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Brian Winkler
Greenhorn
Joined: Jun 05, 2012
Posts: 16
|
|
Bear Bibeault wrote:That error almost always means that the class is trying to be executed in a JRE of an earlier version than the JDK that created it. Are the CentOS and Mac Mini running earlier version of Java than your Pro?
Thanks for your reply...
The CentOS I don't know about... The Mac Mini is mine, and only about two weeks old. I installed the JRE on the Mac Mini right after I purchased it, and the Java control panel showed only one instance and it was version 1.7.0_09... same as the JDK I later installed. Is there any chance I am missing anything?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56221
|
|
|
At the command prompt, what does each respective machine show for:
|
 |
Brian Winkler
Greenhorn
Joined: Jun 05, 2012
Posts: 16
|
|
Bear Bibeault wrote:At the command prompt, what does each respective machine show for:
on the MBP:
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)
on the Mac Mini:
java version "1.7.0_09"
Java(TM) SE Runtime Enviroment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
I dont have the info on the CentOS box, but I will ask him for it. Also, the Mac Mini is working fine now... Ever since I installed the JDK on it. So, I am not sure what the results of java -version were prior to installing it.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56221
|
|
|
Is your IDE perhaps using an older JDK? I know with IntelliJ (the IDE I use) you can select among a number of Java versions.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56221
|
|
|
P.S. I believe that there is a way with javap to find out what version compiled a class file. Never used it, so don't know the details...
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3041
|
|
Bear Bibeault wrote:Is your IDE perhaps using an older JDK? I know with IntelliJ (the IDE I use) you can select among a number of Java versions.
I believe the problem is reversed - if you compile on an old JDK and run on a new JRE you are ok because the new version knows about the old, it is only the reverse which is bad.
And this seems to be the problem the OP is seeing. The error message says "Unsupported major.minor version 51.0." The class version for Java 7 is 51.0, so it means whatever version of Java the user is trying to run on is prior to version 7.
The options are to either ask the user to install Java 7 on CentOS, or to recompile targeting a previous version of Java - assuming you don't use any of the new Java 7 stuff.
|
Steve
|
 |
Brian Winkler
Greenhorn
Joined: Jun 05, 2012
Posts: 16
|
|
Steve Luke wrote:
Bear Bibeault wrote:Is your IDE perhaps using an older JDK? I know with IntelliJ (the IDE I use) you can select among a number of Java versions.
I believe the problem is reversed - if you compile on an old JDK and run on a new JRE you are ok because the new version knows about the old, it is only the reverse which is bad.
And this seems to be the problem the OP is seeing. The error message says "Unsupported major.minor version 51.0." The class version for Java 7 is 51.0, so it means whatever version of Java the user is trying to run on is prior to version 7.
The options are to either ask the user to install Java 7 on CentOS, or to recompile targeting a previous version of Java - assuming you don't use any of the new Java 7 stuff.
This is kind of what I was thinking too. I did some searching on google, and and couldn't find an exact answer... A.) do I have to install the JDK for say java 6, or is it included in the java 7 JDK? and B.) how in Eclipse do I tell it which version of java to compile with?
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3041
|
|
Brian Winkler wrote:A.) do I have to install the JDK for say java 6, or is it included in the java 7 JDK?
You do not need to have different JDKs installed. There are two switches to consider for targeting a specific (minimum) run time:
javac -source 6 -target 6 myclass.java
Will make sure that only features at or before Java6 are accepted, and that the .class file is generate with major.minor version 50.0. I think the -target switch is automatically set to the same value of -source for most versions. This link shows more:
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#options
Brian Winkler wrote:and B.) how in Eclipse do I tell it which version of java to compile with?
Not sure. But if you look through the properties you should see something to a 'Target JRE'. If not then I know there are options to send command line options to the compiler as well someplace in the configuration.
|
 |
sourav jain
Greenhorn
Joined: Nov 19, 2012
Posts: 22
|
|
|
jre means that java runtime envoirments and jdk is java development kit
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2552
|
|
Brian Winkler wrote: B.) how in Eclipse do I tell it which version of java to compile with?
In Eclipse go to Window-> Preferences -> Java -> Compiler.
You see an option for setting the source level.
|
SCJP, SCWCD.
|Asking Good Questions|
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Welcome to the Ranch sourav jain
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14491
|
|
A JDK contains a JRE.
You need a JDK in order to compile code, and a JRE to run code.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Rajdeep Biswas, Your post was moved to a new topic.
|
 |
 |
|
|
subject: JRE vs. JDK
|
|
|