• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JRE vs. JDK

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
lowercase baba
Posts: 12754
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian Winkler
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, here you go, hope this helps.

 
Marshal
Posts: 65107
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Brian Winkler
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the command prompt, what does each respective machine show for:
 
Brian Winkler
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Brian Winkler
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jre means that java runtime envoirments and jdk is java development kit
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Campbell Ritchie
Marshal
Posts: 65107
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch sourav jain
 
Bartender
Posts: 20938
127
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JDK contains a JRE.

You need a JDK in order to compile code, and a JRE to run code.
 
Campbell Ritchie
Marshal
Posts: 65107
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajdeep Biswas,
Your post was moved to a new topic.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!