How to program with Java 1.6 in a Mac? - java

I was working in a Java 1.6 project in Windows, and now I have to work from my laptop, that is a Macbook Pro (Intel Core 2 Duo) with a MacOsX Leopard 10.5.8 installed.
In the same laptop I've worked in the past with Java 1.5 with any problems, but now I can't work with 1.6, and I don't know what I'm doing wrong.
When in a terminal I write: java -version I get java version "1.6.0_26"
But when I'm trying to install last version of Netbeans (7.0.1) I get the message:
It's not possibe to install NetBeans 7.0.1 in this volume. This
software can be installed and work only with Java 6
Then I tried to work with Eclipse. I've download last version of the IDE, and open the project. I get some compile errors (the parts of Java 1.6).
I went to Preferences -> Java -> Compiler->Compiler compliance level from 1.5 to 1.6
Then I get a message that says:
When selecting 1.6 compliance, make sure to have a compatible JRE
installed and activated (currently 1.5) Configure
But when I try to change to 1.6
The selected JRE does not support the current compiler compliance
level of 1.6
What I have to do to work with Java 1.6?
EDIT:
I've noticed that at
/System/Library/Frameworks/JavaVM.framework/Versions/
1.6 seems not to be installed

On OS X Leopard (10.5) the JDK 1.6 can only be used on 64bit-hardware (also in the Apple FAQ). If you are on a 32bit-hardware, you will not be able to run Java 1.6.
If you are on 64bit hardware, you can install it via SoftwareUpdate or via the Developer Tools. To select the running version of Java you can use the Java Preferences.
Here you will find a chart which (Apple)-JDK is running under which OS X version.
There is an "unofficial" port I have not tried: The project SoyLatte brings JDK 1.6 to OS X 10.4. and later - perhaps you can have a try with this.

Related

installing java 7 on Mavericks

I have a new mac with Mavericks (ie without java). I installed java 8, but my grails project not supported java8, and I need to install java7.
How I can to install java 7 manually (java installer will determine the java 8) without uninstalling existing java8?
check out which version is installed
java -version
download and install the version 1.7 from the oracle servers
this should work
Apple disabled older versions of Java. here is the link to the Oracle website. There are further information about new and old java jdk's on Apple Mac https://www.java.com/en/download/faq/java_mac.xml

I updated java but java -version is still showing the old version on mac osx

So I updated java to 1.7 but when I run java -version in terminal it still shows 1.6 as the version.
I updated by going to java.com and downloading the .dmg file and installing that.
Also eclipse still shows 1.6 as the version which I need 1.7.
How can I get java version 1.7 to show up everywhere?
Completely uninstall Java 1.6 and then reinstall 1.7 from scratch, rather than updating.

Eclipse windowbuilder java 1.6 1.7

I have just installed WindowBuilder for Eclipse and java 1.7 JDK, but when I create a new JFrame in Eclipse, and try to open the "design-view" in WindowBuilder I get the following error:
"Eclipse is running under 1.6, but the Java project has a 1.7 Java compliance level, so WindowBuilder will not be able to load classes from the project. Use a lower level of Java for the project, or run Eclipse using a newer Java version."
When I check the properties for the project, it is set to Java Compiler 1.7. When I run a Java -version in my terminal I get:
java version "1.7.0_15"
Java(TM) SE Runtime Environment (build 1.7.0_15-b03)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
I have tried to chance the path to the newest Java, following this link:
Link to Eclipse Wiki
When changing it to:
-vm
/Library/Java/JavaVirtualMachines/jdk1.7.0_15.jdk/Contents/Home/bin/java
I get a error when I try to open Eclipse saying:
"the jvm shared library does not contain the jni_createjavavm symbol"
What's where I am stuck. Anyone how knows how to fix this problem? I have tried using Netbeans, but my Mac and Netbeans are not best friends: Pic of screen-crash
Go to Project Properties and change the project compliance level from 1.7 to 1.6. Also leave the Eclipse running under Java 1.6.
In my case I Change my default java version in my whole OS, I followed the steps in this question!, I am using Debian but you can look for you OS how to make java 1.7 the default java version, in my case I do not need java 1.6 anymore and I set my OS java default version from 1.6 to 1.7 it made eclipse load under my default java version 1.7 and then I changed in Eclipse to all workspace the java to version 1.7.
By doing this eclipse will run with default java version 1.7 of the OS.
But if you still need java 1.6 for the OS and 1.7 just for eclipse, in my case using Debian you need to edit:
vim /etc/eclipse.ini
And following suggestion adding the option "-vm /usr/lib/jvm/java-7-openjdk-amd64/bin/"
Of course you need to know your java 1.7 path, it is an example using my path.
It's up to you to choose any solution by OS to load eclipse from he java version of the OS or changing the eclipse.ini to java 1.7 and leaving java 1.6 as default for OS.

Mint Linux - Downgrade Java to 1.5

Currently, I am running Mint Linux (Release 9). I need to downgrade Java from version 1.6 to 1.5, and have been trying to figure out how to go about this. So far, I've had no luck. The package manager doesn't seem to have it.
Does anyone have any suggestions?
Thanks,
- Chris
As you explained in your comments, you need JDK 5 because you are working on the source code of Android itself and the instructions say:
Ubuntu Linux (64-bit x86)
... JDK 5.0, update 12 or higher.Java 6 is not supported, because of incompatibilities with #Override.
You can do this:
Uninstall any Java that you got via the package system of your Linux distro
Download JDK 5 Update 22 for Linux
Run the JDK installer with sudo, install it wherever you like (for example in /opt or /usr/local)
Set your PATH environment variable to include the bin directory of the JDK
There should be no need to downgrade your Java installation to develop for Java 1.5. If you are using a tool such as Eclipse, you can set the project attributes so that it tests for Java 1.5 compatibility, and gives errors if you use a Java 6 feature. If you absolutely insist on having a Java 1.5 JDK then just install it alongside the default installation and use it in place of Java 1.6.
This should be a question for SuperUser.com, but my recommendation is to download the 1.5 JDK, and change Java path to where you downloaded it.
Or you could use the info on Ubuntu Help, it should work for you since Mint is based on Ubuntu. That link explains how to select the version of Java.

How to install a specific JDK on Mac OS X?

I want to install a specific JDK (the latest for example). For this, I went to the JDK download homepage: http://java.sun.com/javase/downloads/index.jsp.
I looked for a Mac version, but I'm a bit surprised to only see downloadable versions for Linux, Windows and Solaris...
Here's the message for Mac:
"Apple Computer supplies their own version of Java. Use the Software
Update feature (available on the Apple menu) to check that you have
the most up-to-date version of Java for your Mac."
OK BUT... when I update Java with Mac I have a JRE and not a JDK...
I don't understand why a JDK version doesn't exist that is easily downloadable/installable (like a jar to unzip?) for Mac...
In a comment under #Thilo's answer, #mobibob asked how to set JAVA_HOME in your .bash_profile on a Mac. Answer:
export JAVA_HOME=`/usr/libexec/java_home`
This will dynamically assign to JAVA_HOME the location of the first JDK listed in the "General" tab of "Java Preferences" utility.
See Apple Technical Q&A 1170: https://developer.apple.com/library/content/qa/qa1170/_index.html
EDIT:
If you prefer parentheses to backticks for command substitution, this also works:
export JAVA_HOME=$(/usr/libexec/java_home)
As the message says, you have to go to Apple, not Sun, for Java on the Mac. As far as I know, Apple JDK 6 is installed by default on Mac OS X 10.6 (Snow Leopard). Maybe you need to install the developer tools from your Mac OS X installation DVD (the dev tools are an optional install from the OS DVD).
See: http://developer.apple.com/java/
NOTE This answer from 16 Oct 2009 is now outdated; you can get the JDK for Mac OS X from the regular JDK download page on Oracle's website now.
For people using any LION OS X 10.7.X
They uploaded Java SE 6 version 1.6.0_26 available here
http://support.apple.com/kb/dl1421
I bought a MacBook Pro yesterday (Mac OS X v10.8 (Mountain Lion)) and there is no JDK installed by default...
As well as javac, I also found it didn't have packages such as SVN installed. It turns out you can get everything from the Apple developer page (you will need to register with your AppleID). SVN is part of the "Command Line Tools" package.
This is what happens on a fresh MacBook:
Hopefully this will help out other newbies like me ;)
The explanation is that JDK is a bit specific and does not contain the library tools.jar. For my development, I need this library and Mac's JDK doesn't provide it:
(Cf. http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/02-JavaDevTools/JavaDevTools.html)
tools.jar does not exist. Classes usually located here are instead included in classes.jar. Scripts that rely on the existence of tools.jar need to be rewritten accordingly.
It sucks!
The easiest way is to use Homebrew.
Install Homebrew and then:
brew tap caskroom/versions
brew cask install java7
You can list all available versions using the following command:
brew cask search java
Mac comes with the JDK, for more information check:
http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/02-JavaDevTools/JavaDevTools.html
Compiling with -source 1.5 -target 1.5 (in a JDK 6 environment) will honor only language elements that were in 1.5 and prior. Great. But there were no language changes in 6 anyway. Problem with this approach (on Mac with 1.6) is that using classes that came AFTER 1.5 will still compile because they exist in the rt.jar. So one could run in a 1.5 env and get a class not found exception with no prior warning when compiling. I found this out the hard way with javax.swing.event.RowSorterEvent/Listener. Both entered "Since 1.6" but are not caught with -source 1.5
If you installed brew, cmd below will be helpful:
brew cask install java
As of Mac OS X v10.6 (Snow Leopard), you can run Java 6 in 32-bit mode on either 32-bit or 64-bit Intel processor equipped Macs.
If you cannot upgrade to Snow Leopard, Soy Latte is a pre-compiled version of Java 6 for Intel 32-bit.
There are various tricky issues with having multiple versions of Java (Apple's own Java 6 and Oracle JDK 7 or even 8) on one's Mac OS X system, and using different versions for different applications. I spent some time writing up my experience of my experience of installing and configuring various versions of JDK on Mac OS X 10.9.2.
In 2022, give a try to sdkman, is better than brew
curl -s "https://get.sdkman.io" | bash
then open a new shell and try list to see what you could install ;-)
sdk list java
At time of writing you could use:
sdk install java 17.0.1-tem
Check this awesome tool sdkman to manage your jdk and other jdk related tools with great ease!
e.g.
$sdk list java
$sdk install java <VERSION>
Since most answers are out of date, here's what works as of end of 2018 under the assumption that
You want to install the GPL version of OpenJDK.[0]
You do not want to install Homebrew
In that case, grab the desired version from one the many available, freely usable OpenJDK editions, e.g.:
AdoptOpenJDK
Amazon Corretto (Great for production, includes backports)
Oracle GPLv2 OpenJDK
Some of these include installers, but if not you can do the following. Assuming here version 11.0.1 for Mac. In your favorite shell, run:
tar -xzf openjdk-11.0.1_osx-x64_bin.tar.gz
sudo mv jdk-11.0.1.jdk /Library/Java/JavaVirtualMachines
# Fix owner and group
sudo chown -R root:wheel /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk
# (Optional) Check if the new JDK can be found
/usr/libexec/java_home
=> /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
[0] Note that the Oracle branded JDK has significant licensing restrictions allowing you its use basically only for testing, i.e., not for production. If you do not have a support agreement with Oracle, then it seems risky to me to use their JDK, especially since the differences to OpenJDK are minimal.
Edit: added more choices
I think this other Stack Overflow question could help:
How to get JDK 1.5 on Mac OS X
It basically says that if you need to compile or execute a Java application with an older version of the JDK (for example 1.4 or 1.5), you can do it using the 1.6 because it is backwards compatible. To do it so you will need to add the parameter -source 1.5 and/or -target 1.5 in the javac options or in your IDE.
JDK is the Java Development Kit (used to develop Java software).
JRE is the Java Runtime Environment (used to run any .jar file 'Java software').
The JDK contains a JRE inside it.
On Windows when you update Java, it updates the JRE automatically.
On Mac you do not have a JRE separated you have it, but inside the JDK, so when you update Java it will update your JRE which is inside your JDK;
it doesn't install an JDK for you. You need to get it from somewhere else.
As a rule you cannot install other versions of Java on a Mac than those provided by Apple through Software Update. If you need Java 6 you must have a 64-bit Intel computer. You should always have Java 5 and 1.4 and perhaps 1.3 installed if you have at least OS X 10.4.
If you have VERY much elbow grease and is willing to work with beta software you can install the OpenJDK under OS X, but I don't think you want to go there.

Categories