Working with SDKs
- What are SDKs for?
- Supported SDKs
- SDK levels
- SDK contents (classpath, sourcepath, and documentation paths)
- Defining an SDK when creating a project or module
- Managing global, project and module SDKs
- Making Apple JDK sources accessible in IntelliJ IDEA on macOS
What are SDKs for?
IntelliJ IDEA does not include an SDK. So, before you start writing your code, you have to download and install at least one SDK, and define it in IntelliJ IDEA. (You can specify an SDK when creating your first project or at a later time.)
To define an SDK in IntelliJ IDEA, generally, all you have to do is to specify its location. (This location, normally, is referred to as the SDK home directory. This is the directory in which the SDK is installed). Additional SDK adjustments are possible, however, in most of the cases, they are not necessary.
Depending on the nature of your application, you can use:
- Java SE Developments Kits (JDKs) to develop Java desktop and enterprise applications.
- Mobile SDKs (Java Micro Edition (ME) SDKs) to develop applications for Java-enabled mobile devices.
- Android SDKs to develop applications for Android devices.
- Flex and AIR SDKs to develop applications for the Adobe Flash platform.
- Flexmojos SDKs to launch the Flex compiler and debugger. (Such SDKs are created by IntelliJ IDEA automatically when importing Flexmojos projects.)
- IntelliJ Platform Plugin SDKs to develop plugins for IntelliJ IDEA. (An IntelliJ IDEA installation acts as an IntelliJ Platform Plugin SDK.)
Note that the set of supported SDK types depends on the IntelliJ IDEA edition being used (Community or Ultimate) and also on which plugins are currently enabled.
All the SDKs, generally, are global: irrespective of when and where you define an SDK, you can then use it in any of your projects.
One of the SDKs is assigned to a project and is referred to as a project SDK. This SDK is used by default by all the modules of the corresponding project.
A module can use ("inherit") the project SDK, or, alternatively, a module-specific SDK can be specified.
SDK contents (classpath, sourcepath, and documentation paths)
When you define a new SDK, IntelliJ IDEA analyses the contents of the SDK installation folder (home directory) to find out where the corresponding binaries, sources and associated documentation are located. As a result, all the appropriate locations within the SDK are translated into corresponding paths and assigned to one of the following categories:
Classpath. This is a set of paths to directories and archives containing the SDK binaries. For a JDK, for example, this set includes the paths to class directories and JAR files that make up the Java API and its extensions.
You can add more SDK libraries to this set, however, this is never necessary for any standard SDK.
If online documentation is available for the SDK, you can add the corresponding URL to the SDK documentation paths () to be able to access this documentation when needed.
Defining an SDK when creating a project or module
You can define a new SDK when creating a project or module. See e.g. Creating a project in Creating, Running and Packaging Your First Java Application.
As a result, the SDK definition will appear at the IDE level. In addition to that:
- If you defined an SDK when creating a project, the SDK will be assigned to the project as the default project SDK. The module that is created together with the project will inherit the project SDK.
- If you defined an SDK when creating a module, the SDK will be assigned to the module.
Managing global, project and module SDKs
Note that if you change the project SDK, all the modules that are using the default project SDK will change their SDK accordingly.
Making Apple JDK sources accessible in IntelliJ IDEA on macOS
The Apple JDK included in macOS installation doesn't contain the JDK sources. So to make those sources accessible in IntelliJ IDEA, you should download and install the Java for macOS Developer Package and then add the JDK sources contained in this package (
src.jar) to the definition of the corresponding JSDK in IntelliJ IDEA.
- In a Web browser, go to the Downloads for Apple Developers page.
- Sign in to the downloads page using your Apple developer account (Apple ID and password).
- Download and install the Java for macOS Update Developer Package suitable for the macOS version that you are using.
- In IntelliJ IDEA, open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S) and select SDKs.
- Select the Apple JDK of interest. (If the corresponding JDK is not present in the list, add its definition: , etc.)
- On the SDK page shown in the right-hand part of the dialog, select the Sourcepath tab and click (Alt+Insert).
- In the dialog that opens, select the file
src.jarand click OK.
(Usually, this file is located in
<java.version>is your JDK version, for example,
1.6.0_31-b04-415.jdkor something similar.)
- Click OK in the Project Structure dialog.