Skip to content

Ferdinand Agyei-Yeboah

Random Intellji Stuff

December 02, 2020

Background

Some tips on Intellji. The proper Intellji term for a collection of folders is “Project” but I sometimes use the term “Workspace” since it better describes the purpose of Projects.

Creating Intellji workspaces vs. modules

Intellji “Projects” are essentially workspaces. Workspaces are a collection of folders that are related, this generally takes the form of a single business application that might be made up of many services (code repositories). In that case, the workspace would be the collection of all those services.

I like to use an empty project to create a free-form module structure. I keep all my projects in a /workspaces folder that is separate from the actual source code for the modules. The project can be in a separate folder from each of the modules because the project is essentially just metadata specifying all the modules in a project. When you open the project it will load all the modules from their respective locations.

If you create a specific project from the project wizard, ex: maven, it will create a project and module at the same time. This somewhat conflates the two concepts since your project and module will have the same name and location, and any other modules you add would probably be in a different location (and the name of the project wouldn’t make sense now). It’s fine for a single service, but for multiple related services it makes more sense to create an empty project first.

When you have a project created, you can add new services by simply going to Add New Module or Add Existing Module (import code already on system).

Importing an existing maven project

If you have an existing maven project, that is not an intellji module, you can import it by going to new module and then clicking on the pom.xml to import it. Go through the steps and it will create an intellji module (.iml file).

If you have an existing maven project as an intellji module, you can select the .iml file to import it as a module in your current project.

[TODO: Look into how importing the same module in multiple projects goes. Is it fine or what.]

Importing “Normal” folders that contain a maven project

Assuming you have a project, you would add the folder as an empty module.

Go to File -> Project Structure and then add a new module and choose empty. The content root may get messed up after it’s imported. Go in project structure and fix it. To add any maven applications that are in subfolders of your module, go to the pom.xml and right click “Add as maven project”.

Bookmarking file locations

A useful feature is bookmarking file locations. Right click in code editor -> Add bookmark.

Updating a maven project

You can configure Intellji to auto-import on changes to pom.xml but if that doesn’t work or if you want to manually update do the following: Right click pom.xml -> Maven -> Update Project

Helpful Shortcuts

Go To Implementation: Ctrl + Alt + B
Search files: Shift, Shift
Find in files: Ctrl + F
Replace in files: Ctrl + R


Software Engineering Tutorials & Best Practices