简体   繁体   中英

How to setup libraries for IntelliJ 13 on Mac with JDK 1.8

I recently installed the Java 1.8 Update 20 JRE on my Mac running OSX 10.9.4. After that, I also added the JDK of 1.8.0_20. When I go into Terminal and execute "java -version" or "javac -version", each time I get "1.8.0_20" as a result. For me, this means that both JRE and JDK 1.8 are the System standard right now (I might be wrong on this).

So, I also add IntelliJ IDEA 13.1 and open it. I logged into GitHub using my credentials and it worked. So from the launcher window, I proceed Configure → Project Defaults → Project Structure. From here I firstly click the "New" button next to "No SDK" and select JDK. It automatically brings me to /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home. Just to make sure I select the JDK itself, I back off into ~/JavaVirtualMachines/ and select the jdk1.8.0_20.jdk, hitting return. This is now recognized as "1.8" in IntelliJ.

On the left hand side, I now go to Libraries and hit the "+" sign. This also automatically brings me to /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/jre/lib. I know that it has to add all the .jar files in this folder, so I highlight using SHIFT + CLICK the entire contents of the folder and click "Ok". This is now library "ext" (don't know where that name comes from). I click Apply and Ok and go back to the Quick Start menu.

Selecting "Create New Project", I leave the template for Java and see that the Project SDK has been set as 1.8 (Java version "1.8.0_20"). Underneath it gives me the option to tick for "Groovy" (again, no idea what that is) and lastly, the library... Only that the line "Use library:" returns "[No library specified]". Even when I tick Groovy and the library field becomes clickable, it still does not find the before-created Java library. Nevermind that, I untick Groovy and go to write some simple Java code: Under the project name, in its src folder, I create a class and write:

public class main {

    public static void main (String[] args){

        System.out.println("Hello World!");

    }

}

When I try to run the code, the button for it is greyed out. I have been searching the SO forum for a while, but it doesn't seem that anyone on JDK8 and IntelliJ 13 had this exact problem. Any ideas?

Okay, I figured this out: Removed JDK 1.8 with its JRE for purpose of a clean install down the line.

Went into Eclipse and tried to run the same code with no trouble. So I opened IDEA and removed the JDK and lib that I added manually. Then, I inserted back the 1.7 JDK and left it as such. Opened a black project and did not tick Groovy or the library option. For some reason, IDEA now reads the JDK internal Lib and includes it in the project. Created a new "main" class and wrote the same code as above. Then I checked the run options and although 1 was greyed out, the other worked.

From then on I installed JDK 1.8 again and tried the same, everything works just fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM