File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes IDEs, Version Control and other tools and the fly likes Eclipse - compile with JDK 6, run on JVM 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Eclipse - compile with JDK 6, run on JVM 5" Watch "Eclipse - compile with JDK 6, run on JVM 5" New topic
Author

Eclipse - compile with JDK 6, run on JVM 5

Maciej Drozdzowski
Ranch Hand

Joined: Dec 30, 2009
Posts: 40

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

Joined: Sep 29, 2008
Posts: 12617

(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

Joined: Jun 25, 2001
Posts: 15641
    
  15

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's not really a reason, though, that's just saying you can do it.
Maciej Drozdzowski
Ranch Hand

Joined: Dec 30, 2009
Posts: 40

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jun 25, 2001
Posts: 15641
    
  15

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Dec 30, 2009
Posts: 40

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

Joined: May 14, 2008
Posts: 5778
    
    7

Under project properties, in the Java Compiler section, choose 1.5 from the "Generate .class files compatibility"


JBoss In Action
Maciej Drozdzowski
Ranch Hand

Joined: Dec 30, 2009
Posts: 40

ok, i had to recreate my workspace from scratch, it was eclipse's fault.
task easier than it seemed.
thank you all.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Eclipse - compile with JDK 6, run on JVM 5
 
Similar Threads
Why Just run in my PC ?
UnsupportedClassVersionError: org/apache/poi/hssf/usermodel/HSSFWorkbook (Unsupported major.minor ve
Getting UnsupportedClassVersionError Unsupported major.minor version 49.0
Applet not working on old computers
Why can't I run these jar files on a PC that doesn't have the JRE 6?