Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eclipse - compile with JDK 6, run on JVM 5

 
Maciej Drozdzowski
Ranch Hand
Posts: 40
Google Web Toolkit Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been trying to achieve this: compile my code using JDK 6 but run the application on JVM 5.
I know, exceptions for not found classes and methods will be thrown.
Can this be done?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Is there a reason you won't just compile with 1.5? Personally I think the possible headaches of delivering something they can't run aren't worth it.)
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:(Is there a reason you won't just compile with 1.5? Personally I think the possible headaches of delivering something they can't run aren't worth it.)


I have one. Java 6 is my installed JVM for Eclipse, but I was running apps using Apache OpenJPA, which at the time required Java 5 settings. I just overrode the project settings on the projects of interest to target Java 5.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not really a reason, though, that's just saying you can do it.
 
Maciej Drozdzowski
Ranch Hand
Posts: 40
Google Web Toolkit Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the reason is - i often like to get into java sources or use some new features (ones that appeared in 6.0).
then i can look into the new features, learn them, etc etc. i don't want to be behind ;)
compiler will allow for this, but at runtime i will get my ass kicked.

if i have to stick to 5.0 - i just don't see the new 6.0 stuff.

why do i have to stick to 5.0 - because this is how we do at work and i have to obey these rules.


Tim - any idea how to do it in a regular case? just plain applications (like one file and a main method)? or when i run them on Tomcat?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand the problem: you can have multiple JDKs installed, run Eclipse using 1.6 and use it for whatever projects you want, but compile specific projects with specific versions.

In the project settings you can set the compiler compliance level and set the generated class file compatibility.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you work in an enlightened shop or happen to be one of the fortunate few who are allowed liberties, you're better off leaving Java 6 on your home computer. And if your shop isn't at least looking at Java 6 at this point, it's a good idea the keep the old CV polished up.

When you pick source and object compatibility levels in Eclipse, they apply to the entire project. You can include components compiled under Java 5, 1.4, or whatever in a Java 6 project, of course, but anything you compile yourself will be done according to the rules of that project. In order to do otherwise, you'd have to create the exceptional components in some other project that had a different Java version setting and import them.

To tell you the truth, I don't really notice much difference between Java 5 and Java 6, and I do a lot of bouncing back and forth. The only thing I can recall without RTFM'ing is that Java6 handles annotation processing better, but I only do annotation stuff about once a year. Then again, I'm not using Java 6 features just because I can - only because I need to.

Java 1.4, on the other hand...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interface @Override is the one I use the most--not much of a feature, but still--handy. The other stuff I use is some Swing stuff, but... not as handy as @Override.
 
Maciej Drozdzowski
Ranch Hand
Posts: 40
Google Web Toolkit Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
either i'm retarded or my eclipse doesn't really like me.
i thought it was somewhere outside that compiler compatibility preferences window.
either way, this thing doesn't want to work for me
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Under project properties, in the Java Compiler section, choose 1.5 from the "Generate .class files compatibility"
 
Maciej Drozdzowski
Ranch Hand
Posts: 40
Google Web Toolkit Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, i had to recreate my workspace from scratch, it was eclipse's fault.
task easier than it seemed.
thank you all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic