LoginSignup
21
21

More than 5 years have passed since last update.

Eclipseの起動に使用するJDKを指定する(Mac)

Last updated at Posted at 2015-01-14

 Java8をインストールした環境では、GAEにデプロイができなくなる場合があります。
 その原因は、GAEがJava7しかサポートしていないため、バーションのミスマッチが起きていることにあります。

 GAEへデプロイする際にクライアント側でコンパイル作業等をおこなうのですが、その時に使用されるJavaはプロジェクトで設定されているものではなく、Eclipseを起動した際のJDKが使用されます。EclipseをJava8で起動していると、プロジェクトでJava7を指定しててもバージョンがあわなくなってしまうのです。

 ですので、ここではMacでJavaのバージョンを指定して起動する方法を説明します。

前提条件

Eclipseがインストールされていること
JDK7がインストールされていること

Javaのインストール先を調べる

コンソールを開いて/usr/libexec/java_home -Vと入力してください。
たとえば、私の環境では次のように表示されます。

java_homeの実行結果
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (4):
    1.8.0_25, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
    1.7.0_71, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
    1.6.0_65-b14-466.1, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-466.1, i386:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

ここから、JVMが4つインストールされていることや、それぞれのインストール先が分かります。
今回はJava7が目当てですので、"Java SE 7"の行の/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Homeの箇所をメモしておきます。

設定ファイルを書き換える

 それでは、次にEclipseの設定ファイルを書き換えていきます。
まずは、eclipse.appのコンテキストメニューを表示して、「パッケージの内容を表示」を選択します。

eclipseの中身

そうするとeclipse.appの中身が表示されるのでContentsフォルダの下のInfo.plistファイルを適当なテキスト・エディターで開いてください。
開いたら大体59行目あたりに次のようなコードがあるかと思います

Info.plist(編集前)
    <key>Eclipse</key>
        <array>
            <!-- to use a specific Java version (instead of the platform's default) uncomment one of the following options,
                    or add a VM found via $/usr/libexec/java_home -V
                <string>-vm</string><string>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Commands/java</string>
                <string>-vm</string><string>/Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Home/bin/java</string>
            -->
            <string>-keyring</string><string>~/.eclipse_keyring</string>
            <string>-showlocation</string>
            <!-- WARNING:
                If you try to add a single VM argument (-vmargs) here,
                *all* vmargs specified in eclipse.ini will be ignored.
                We recommend to add all arguments in eclipse.ini
             -->
        </array>

ここのコメントの次の行に<string>-vm</string><string>/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin</string>と追記してください。
結果として次のようになるはずです。

Info.plist(編集後)
    <key>Eclipse</key>
        <array>
            <!-- to use a specific Java version (instead of the platform's default) uncomment one of the following options,
                    or add a VM found via $/usr/libexec/java_home -V
                <string>-vm</string><string>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Commands/java</string>
                <string>-vm</string><string>/Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Home/bin/java</string>
            -->
            <string>-vm</string><string>/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin</string>
            <string>-keyring</string><string>~/.eclipse_keyring</string>
            <string>-showlocation</string>
            <!-- WARNING:
                If you try to add a single VM argument (-vmargs) here,
                *all* vmargs specified in eclipse.ini will be ignored.
                We recommend to add all arguments in eclipse.ini
             -->
        </array>

ここまでできたら保存して、エディタを閉じて完了です。
Eclipseをクリーン起動させましょう。 :laughing:

21
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
21