From the course: IntelliJ IDEA Community Edition Essential Training

Explore the structure of a Java project

From the course: IntelliJ IDEA Community Edition Essential Training

Start my 1-month free trial

Explore the structure of a Java project

- [Instructor] The structure of a Java project in IntelliJ IDEA, depends on the options that you selected when you created the project. The simplest projects, like the one I'm looking at now have a single file and that file's directory location, will depend on the package. In Java, for example, the package also translates to a directory structure. So in your source code root directory, you'll have a com subdirectory, an example subdirectory of that and then the file, main.java will be in that directory. You can see that directory structure in the project window which you can open by clicking on the tab in the top left, or by going to the menu and selecting view, tool windows, project, or by pressing the associated keyboard shortcut. The project window points at the project root directory. On Mac the tilty character means the home directory and if you're working on Windows you'll see something similar. The idea projects directory is just the default directory name, where new projects are created but there is nothing magical about that directory name. You could create your project somewhere else If you like. Under the project directory, you'll see three subdirectories minimally. The SRC or source directory will contain your code. By default package directories that are empty will be compressed. So, while there's actually a com directory with an example subdirectory, the project window is showing that as a single entry. If you want to see that in a tree, click on the gear icon and then unselect compact middle packages and you'll see the true subdirectory structure displayed. The out directory is where your compiled classes are placed. Under out there'll be a production subdirectory and then another subdirectory under that with the name of the project. From there, once again you'll see the package structure. In this case a com directory with an example, subdirectory and then the compiled class. If I go back to that configuration and turn compact middle packages back on, you'll see that it's compressed in the source directory but not in the out directory. The .idea directory contains a bunch of configuration files. Many of them will be regenerated automatically if you were to delete them, but some of them contain important information that you shouldn't change unless you know exactly what you're doing. So for example, the modules.xml file controls the modules. A single project can have one or more modules. By default as simple Java application will just have one module like this one, workspace.xml has all kinds of settings that manage the appearance and behavior of the editor and other elements of the user interface. When you're in this project and .gitignore is an important file when you're working with source control using git, say on git hub. You can add names of files here to indicate that you don't want to check in those files and you don't want to track them in the source control system. Down here there's a virtual subdirectory called External Libraries. Most of the time you could ignore this. This shows all the different core libraries in the standard JD cave runtime. So for example, there's java.rmi, java.scripting, java.sql, and so on. You'll never change these settings but this tool gives you troubleshooting capability. Say if you're not able to find a particular class that you think should be there. And finally, there's an IML file. It'll have the same name as the project and this is a critical file that manages all the other files, the modules, the workspace setting, the folder where you're creating your source code files and so on. Now, as you add more capabilities to your project say if you're using dependencies and you're using the Maven or Gradle Frameworks, you'll see more directories and more configuration files. This is just the simplest structure that you're going to see when you create a brand new Java project in IntelliJ IDEA.

Contents