• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Eclipse - compile with JDK 6, run on JVM 5

 
Ranch Hand
Posts: 40
Google Web Toolkit Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
To do a great right, do a little wrong - shakepeare. twisted little ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic