1

On my work computer, I have Windows 7 x64 with JDK 1.7 installed. I created a project in Netbeans and all went well. I then copied my project onto my home computer that is running Mac OS X 10.6, which is running JDK 1.6. The build fails with an error message about an unsupported major.minor version .51. Googling and searching concludes that it is because of a JDK version mismatch. Oracle does not allow JDK 1.7 to be installed on Mac OS X 10.6, so I am stuck with JDK 1.6 on my Mac.

Is there a way I can take my 1.7 code and get it to build and run on my Mac OS X 10.6 running JDK 1.6? Or is there way I can take my code back to my JDK 1.7 machine and downgrade the compatibility to 1.6? Basically I need the code to run on my work computer and home computer.

4
  • How are you building it?? Netbeans, Eclipse, Hand Commented Aug 15, 2012 at 4:13
  • I am building it via Netbeans Commented Aug 15, 2012 at 4:15
  • 1
    Just install openJdk7 on your system. Did it on my macbook pro and it runs like a charm. Commented Aug 15, 2012 at 4:21
  • Just got the news: Jdk 7u6 is available for MacOS! Happy downloading! Commented Aug 15, 2012 at 21:14

3 Answers 3

3

Open Project Properties in NetBeans and set the platform and language level to 6 (or 1.6). Then clean and build. You can't use any Java 7 features though. You should be able to do this with your existing Java 7 install on Windows; you shouldn't need to install Java 6.

Alternatively, you can install an unofficial OpenJDK 7 build on your Mac running 10.6. Look here for downloads:

http://code.google.com/p/openjdk-osx-build/

Sign up to request clarification or add additional context in comments.

Comments

3

Unless you are using new 1.7 syntax/libraries, you should have no problem building your classes with JDK 1.6

You can also generate 1.6 compatible .class with 1.7 compiler, something like running

javac -source 1.6 -target 1.6 MyClass.java

or if you are using Eclipse, you can set this in a setting dialog.

So the answer is, both ways may work for you.


edit:

corrected my answer.

-source has to be 1.6

Thanks to Stuart Marks for pointing it out!

2 Comments

Will this downgrade my 1.7 code into 1.6 so that I can then run the code on my Mac OS X 10.6 which uses JDK 1.6? I want the Java source code to work on my Windows and Mac machines and be able to build on both machines.
Nope, won't work. You can't use Java 7 features and target 6, because 7's language features have library dependencies. You have to set both source and target to 1.6.
2

This will require you to have Java 1.6 installed on you Windows box. There a syntax incompatibilities between 1.7 & 1.6 (as well as some API differences).

In Netbeans, right click the project node and select "Properties". From the properties dialog, select sources. At the bottom of the dialog, you should see "Source/Binary Format", from the drop down, select "JDK 6"

Select "Libraries". At the top of the dialog, you should see "Java Platform", from the drop down, you will need to select "JDK 1.6"

If you can't find it, click "Manage Platforms". Click "Add Platform", browse to where you installed Java 6 (usually in C:\Program Files\Java) and select it. Click "Finish".

Now you should be able to find it

UPDATE

From comments made by "su-", you may be able to get away with simply changing the "Source/Binary Format" option to 1.6

2 Comments

THANK YOU! Modifying the properties of the project and setting the source/binary format to 1.6 worked! I assume this should give me no troubles when I run the same 1.6 code in JDK 1.7? Worst case, I can just uninstall JDK 1.7 at work and revert to JDK 1.6.
1.7 should be backwards compatible with 1.6 binaries, just not the other way round ;) - Should mention, you won't be able to use the 1.7 features or API enhancements, you'll need to stick with 1.6 API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.