banner



How To Create Package In Intellij

Add items to your project

Once you have created a project, you can start adding new items: create directories and packages, add new classes, import resources, and extend your project by adding more modules.

Create new items

Create a new directory

  1. In the Project tool window (Alt+1), right-click the node in which you want to create a new directory and select .

    Alternatively, select the node, press Alt+Insert, and click Directory.

  2. Name the new directory and press Enter.

    If you want to create several nested directories, specify their names separated with slashes, for example: folder/new-folder.

    Creating a new directory

Create a new package

Packages in Java are used for grouping classes that belong to the same category or provide similar functionality, for structuring and organizing large applications with hundreds of classes.

  1. In the Project tool window (Alt+1), right-click the node within the Sources Root the Sources root icon or Test Sources Root the Test Sources root in which you want to create a new package, and click .

    Alternatively, select the node, press Alt+Insert, and click Package.

  2. Name the new package and press Enter.

    Write package names in lowercase letters. There are some other naming conventions for packages in Java that you should follow.

    Creating a new Java package

Create a new empty file

  1. In the Project tool window (Alt+1), right-click the node in which you want to create a new file and click .

    Alternatively, select the node, press Alt+Insert, and click File.

  2. Name the new file and specify its extension, for example: File.js, and press Enter.

    If the extension you have specified is not associated with any of the file types recognized by IntelliJ IDEA, the Register New File Type Association dialog is displayed. In this dialog, you can associate the extension with one of the recognized file types.

Create a new Java class

  1. In the Project tool window (Alt+1), right-click the node in which you want to create a new class and select .

    Alternatively, select the node, press Alt+Insert, and select Java Class.

  2. Name the new class and press Enter.

    Follow the Java naming convention as you create new classes.

    Creating a new Java Class

Together with the file, IntelliJ IDEA automatically generates the class declaration.

This is done by means of file templates. Depending on the type of the file that you create, the IDE inserts initial code and formatting that is expected to be in all files of that type. For more information on how to use and configure templates, refer to File templates.

Create a new module

Modules allow you to combine several technologies and frameworks in one application. In IntelliJ IDEA, you can create several modules in one project and each of them can be responsible for its own framework.

  1. Right-click the top-level directory in the Project tool window and select . The New Module wizard opens.

  2. From the list on the left, select a module type.

  3. In the right-hand part of the dialog, select an SDK that you want to use from the Module SDK list. You can use the project SDK or specify a new one.

  4. In the Additional Libraries and Frameworks section, select additional assets that you want to use in this module.

  5. On the next step, name the module and specify the location of the content root and the .iml file. You can place them within or outside of the project.

  6. Click Finish.

    Adding a new module to a project

For more information on modules in IntelliJ IDEA, refer to Modules.

Import items

Import files

You can import files to your project using any of the following ways:

  • Drag the file from your system file manager to the necessary node in the Project tool window.

  • Copy the file in the system file manager by pressing Ctrl+C and then paste in to the necessary node in the IDE Project tool window by pressing Ctrl+V.

  • Manually move the file to the project folder in your system file manager.

Example: Import an image

Images belong to resource files. They should be stored in a dedicated folder – Resources Root. If you don't have this folder in your project, create a new directory, right-click it in the Project tool window, and select .

  1. Copy the file in the file manager and then paste in to the folder with resource files in the IDE Project tool window.

  2. In the dialog that opens, edit the filename and the target location if necessary. Click OK.

  3. Right-click the pasted image in the Project tool window and select .

  4. In the class in which you want to use the image, place the caret at the necessary line and press Ctrl+V to paste the path to the image.

    Run the class to make sure that the image is inserted correctly.

Import an existing module

You can import a module to your project by adding the .iml file from another project:

  1. From the main menu, select .

  2. In the dialog that opens, specify the path the .iml file of the module that you want to import, and click Open.

    By doing so, you are attaching another module to the project without physically moving any files. If you don't need the modules to be located in one folder, the module import is finished, and you can start working with the project normally.

For more information on modules in IntelliJ IDEA, refer to Modules.

Last modified: 12 April 2021

How To Create Package In Intellij

Source: https://www.jetbrains.com/help/idea/add-items-to-project.html

Posted by: serranopentagess.blogspot.com

0 Response to "How To Create Package In Intellij"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel