486

I build in maven multiple projects (let's name them A,B,C). Project A uses .jar of project B which uses .jar of project C.

I am modifying the code of all A/B/C projects, (A is MVC app, B are business services and C is some shared layer).

The thing is, in Eclipse/NetBeans I can see all of them at once and it's comfortable to modify them. In IDEA though, I have to open 3 instances (or n instances) of IntelliJ IDEA.

Am I missing something? Is there better approach when using IntelliJ? This is the biggest downside of IntelliJ for me atm.

starball
  • 20,030
  • 7
  • 43
  • 238
Xorty
  • 18,367
  • 27
  • 104
  • 155
  • 14
    Looking through the answers to date, the basic gist I see is that IntelliJ defines what Eclipse calls "projects" as modules, and "workspaces" as projects. The idea is to ensure that modules in the same project are fairly related. So if project A depends on project B, but both are totally unrelated to project C, it would be good to open projects A and B as modules in the same IntelliJ project, while opening C in a separate project in a second IntelliJ instance. You can agree or disagree with the design, but (assuming I've correctly captured the idea) I honor the thought behind it. – John Chesshir Dec 19 '17 at 15:42
  • It has been changed now, you can follow this tutorial. https://codedaily.in/how-to-open-multiple-projects-in-intellij-idea/ – DeepanshuJ Sep 28 '22 at 02:23
  • @DeepanshuJ, "Merge All Project Windows" is available only for macOS according to https://blog.jetbrains.com/idea/2022/07/intellij-idea-2022-2/ – Leponzo Dec 21 '22 at 20:24

25 Answers25

529

I think this has improved with recent versions of IntelliJ. In my current version (12.0.2), you can add any number of separate Maven projects to the same "workspace".

The simplest way I've found to do this is to click the little + icon in the "Maven Projects" window (View > Tool Windows > Maven Projects) and then select the additional pom file you want to import.

Weslor
  • 22,180
  • 2
  • 20
  • 31
Viktor Nordling
  • 8,694
  • 4
  • 26
  • 23
  • 3
    Just to add: once the Maven Project is added it will load in the Project panel if it's a local project. – Aram Kocharyan Jan 04 '14 at 12:14
  • Is there a way to save such state in order not to repeat all POM opening later? – Cleankod Nov 26 '14 at 07:31
  • 11
    If these projects are located in different git repositories, you can check 'Control repositories synchronously' in the settings (Settings > Version Control > Git). IntelliJ will keep pushes, updates and branch selection synced over the multiple projects. – Tim Van Laer Jul 13 '15 at 15:25
  • 18
    For those that are new to IntelliJ and don't know where the "Maven Projects" window is: top right corner. – dustin.schultz Mar 08 '16 at 22:55
  • You should also modify the iml file in your main project to make sure that it picks up the module dependency rather than library dependency. – anirus Jan 26 '17 at 14:24
  • 1
    With 2017 version it's different, refer to https://www.jetbrains.com/help/idea/2017.1/maven-projects-tool-window.html – vikramvi May 29 '17 at 09:58
  • File > Import project, or right mouse-click > Import project in the project explorer was too difficult I guess. Lol. – html_programmer Oct 14 '18 at 13:53
  • 1
    Also, make sure that the `version` in the project B's pom.xml matches the version in Project A's pom.xml. So that IntelliJ can open the source file when you click on a class in Project A that has its source in Project B, otherwise you'll get the `.class` file opened instead. – Miguel Reyes Nov 14 '18 at 19:54
  • 5
    So if you need multiple projects open, but they're Gradle or Ant projects, you're still out of luck. No thanks... I need to be able to have all 3 open, like NetBeans and Eclipse allow. Lack of a proper workspace is the #1 reason I still don't use IJ. – Manius Jan 23 '19 at 06:44
  • 1
    View > Tool Windows > Maven > An inline Window Opens > Click on Plus(+) Sign > Choose POM File of the Project You want to add in Workspace/Window > OK – Karan Kaw Apr 12 '21 at 07:16
315

Step 1: open "Maven Projects"

enter image description here

Step 2: select the project you want to import:

enter image description here

Tho
  • 23,158
  • 6
  • 60
  • 47
203

Prequisite

Having all the related projects in the same root directory can be helpful.

Steps

1) First you create a new Empty project

New empty project


2) Then you select the root directory of all your projects.

This will create a empty project, with a .idea directory that will simply remember the module organisation we are about to do in the next step

Select root directory


3) Then, in the next window, you import the different projects as modules

Import projects as modules


4) In the next window, to import each project, simply double click on the build.gradle, or pom.xml

The project will be imported as a new module. Select build file


5) Done, you now have all your projects as modules, opened on the same IntelliJ project

Result

mrbela
  • 4,477
  • 9
  • 44
  • 79
ThisIsFlorianK
  • 2,281
  • 1
  • 11
  • 13
  • 8
    you have THE solution. But your 'Prequisite Having all the related projects in the same root directory.' is NOT required. I tried for maven projects and it works OK with Intelllij version 2017.3. I haven't tried with intellij standard modules though. – Gauthier Peel Feb 28 '18 at 18:52
  • This is what I've been doing for Maven, Gradle and SBT projects. Adding multiple SBT projects seems to be broken though for more than a year now. You can still add but when you refresh SBT projects in the sbt panel, they get messed up. – Nader Ghanbari Nov 25 '18 at 21:04
  • do you know what is this `maven-archiver` project that is added along with the module? – vault Dec 18 '18 at 12:42
  • Still seems like another poor solution. Why should I need to place a framework library project and derivative projects into the same folder? Particularly if I use that framework lib for multiple unrelated derivative projects, you'd need multiple clones... – Manius Jan 23 '19 at 07:25
  • Now I see this works even if they aren't in the same folder - but I wonder if it has any bad side effects, such as rebuilding *all* projects when you only want to build one "module" (project). – Manius Jan 26 '19 at 18:02
  • 3
    Worked for me with Intellij Idea 2018.3 and Gradle. – incises Mar 11 '19 at 09:35
  • 3
    What if you have run configurations? All macros are pointing to the "true" project root, not on the root of the module you imported, which means you have to use absolute paths in your VM Options. Anyone got a solution for this? EDIT: Yes, I just used $MODULE_DIR$ for that, and it worked. – Roger Aug 28 '19 at 09:18
  • This solution does not allow importing one module into another. Gradle recognizes if you add implementation project(":project") and put it in settings.gradle as well, but IntelliJ IDE shows "unresolved reference". <- Anyone else facing this? Did you find the solution? – Aditya Anand Feb 02 '20 at 16:29
  • This is NOT multiple projects in one window! When you hit Build, it recompiles ALL projects, instead of only the active project. (because there IS only one active project, as opposed to Eclipse) – Mark Jeronimus Mar 19 '23 at 10:02
164

Yes, your intuition was good. You shouldn't use three instances of intellij. You can open one Project and add other 'parts' of application as Modules. Add them via project browser, default hotkey is alt+1

ŁukaszBachman
  • 33,595
  • 11
  • 64
  • 74
  • 1
    I'm doing the same: import the main project, then I import my second project using 'import module', but later than - I got "These modules have been removed from maven structure:... Do you want them to be removed from the project too?" - Then I press 'No'. But this dialog appears many times. What can I do? –  Sep 25 '14 at 01:46
  • 3
    @redDevil which one? – Piotr Findeisen Nov 15 '16 at 05:20
  • 4
    @redDevil No! This answer is more general, if you have non-maven projects this answer is better since the top voted answer simply does not cover them. The two answers tackle different situations and are equally relevant, no one is *better* than the other. – luk2302 Jul 13 '17 at 07:48
  • 2
    This is better than the "Maven only" answer but it doesn't help if you have unrelated projects that you want simultaneously visible (ex. easy access to refer to another project's code), or if you support a library which is a dependency of the project you're focused on. Extremely frustrating how IJ didn't use the Eclipse/NetBeans model here, it's the main thing preventing me from switching to IJ. – Manius Jan 26 '19 at 17:48
  • What I'd like to see in IntelliJ is not listing all the projects in the project explorer as it just makes things more complicated but I want to see a new option say "Open Project" with which is shows a smart view of my workspace and then I select my project. Currently the Open menu item displays the open dialog similar to the file system open dialog and then I have to look for the directory that I know has my project in it. – xbmono May 11 '21 at 00:41
  • How do I "Add them via project browser" - could you specify details, please? – nsandersen Aug 03 '21 at 21:48
71

In IntelliJ 14.1.2, I did it like following:

Select File->Project Structure->Modules.

Select + and Import Module and select the directory of your project(or directory where pom exists) and click OK.

Follow through the next flow of screens and after you click Finish, you should see the project alongside your existing one.

enter image description here

Neo
  • 4,640
  • 5
  • 39
  • 53
55

None of the solutions worked for me, since I am not working on Maven projects. There is a simpler solution. Go to:

File->Project Structure->Modules.

enter image description here

Instead of adding module, simply click the third option (copy). Browse your local directory and select the project you would like to add. Module name will resolve automatically. That's it.

Update: When you want to reopen to project with multiple sub-projects, in order to avoid re-doing steps as described above, just go to File->Open Recent->'Your Big Project'.

gmode
  • 3,601
  • 4
  • 31
  • 39
  • 2
    Yes ... oh Yes .... This is the solution that I'm looking for. Importing as maven module or project do not generate `.idea` and `xxx.iml` files. This may causes problems with **apache tiles**. I'm using with version `2018.1.5`. Thank you very very much. – Cataclysm Jun 23 '18 at 20:28
  • This is amazing! Only downside is using the IDE only as an editor and still having to navigate to the correct folder to compile and run. Anyone have an easy way to use this solution for multiple folders (copied modules) and still compile and run in the editor? – Greg Hilston Sep 08 '19 at 19:20
  • Stop looking around and follow this. This is the correct answer for the question. – Lincoln Oct 23 '20 at 23:07
32

Since macOS Big Sur and IntelliJ IDEA 2020.3.2 you can use "open projects in tabs on macOS Big Sur" feature. To use it, you have to enable this feature in your system settings:

System Preferences -> General -> Prefer tabs [always] when opening documents

enter image description here

After this step, when you will try to open second project in IntelliJ, choose New Window (yes, New Window, not This Window).

enter image description here

It should result with opening new project in same window, but in the new card:

enter image description here

pitagoras3
  • 1,988
  • 2
  • 14
  • 18
  • 2
    unfortunately this feature stopped working for me. is anyone facing this issue? – Spartan Jan 06 '22 at 04:35
  • It kind of works and is kind of broken. For example if I open two projects in different windows and choose File|Project structure it always shows the structure of the first project I opened even if I do this in the second window, and these modal dialogs are modal to all open windows. – bikeman868 May 13 '22 at 19:59
  • 1
    @Spartan, "Merge All Project Windows" is available in [2022.2](https://blog.jetbrains.com/idea/2022/07/intellij-idea-2022-2). – Leponzo Dec 21 '22 at 20:25
14

To expand @Neo answer: after choosing your directory. select import module from external model and choose your model (maven in this case).

choose model

Then check keep project files option from next dialog. It will keep all files in original directory.

options

Your final project structure would be something like this.

structure

Now you can add your module as dependency to other module's pom.xml and if you change the source code of your dependencies, Intellij takes care of updating your project (there is no need to run mvn build manually for dependencies)

artronics
  • 1,399
  • 2
  • 19
  • 28
11
  • new empty project
  • File -> New -> Module from Existing Sources
1lOtzM291W
  • 450
  • 6
  • 10
9

For who uses Gradle can also avail the same:

enter image description here

enter image description here

Go to: 1. View --> Tool Windows --> Gradle 2. Click on the + button and add your build.gradle file

  • Are you using the Community Edition or the Ultimate Edition? I am new to Intellij and have only got CE (2019.3.3). This does not have Gradle in that menu. – mike rodent Mar 07 '20 at 17:13
8

Open preference -> appearance & behaviour -> System settings -> select (open project in new window) then apply.enter image description here

Then you could open and edit multiple projects.

Raymond
  • 350
  • 3
  • 9
  • 9
    This is exactly what the OP is trying to avoid. He wants them in the same window, all three projects at once. – Simon Forsberg Aug 04 '17 at 07:37
  • @SimonForsberg yes, but he also needs to change the settings here to run many projects in the same window that other posts don't show. – Arefe Apr 09 '21 at 11:05
6

You can use Armory plugin which makes switching between projects comfortable. The default shortcut for Project List is Alt + A.

Screenshot of Project List window

By default currently opened projects are displayed at the top of this list (with bold style).

krock
  • 28,904
  • 13
  • 79
  • 85
PHPLego
  • 279
  • 3
  • 6
  • Turned out to be "Not compatible with the version of your running IDE (IntelliJ IDEA 2021.2.3)". I was surprised at this. – WebComer Mar 10 '22 at 12:37
5

Use the button for the add maven projects and go inside the folder of the project. Then, select the pom.xml file and add them in the IntelliJ.

enter image description here

Arefe
  • 11,321
  • 18
  • 114
  • 168
4

Press "F4" on windows which will open up "Project Structure" and then click "+" icon or "Alt + Insert" to select a new project to be imported; then click OK button...

Akshay Lokur
  • 6,680
  • 13
  • 43
  • 62
  • perhaps, write what the F4 suppose to do as people use key mapping and that makes it different for everyone. – Arefe Jan 31 '22 at 06:15
3

To Intellij IDEA 2019.2, F4 + click on module, click to + for add any project from your HDD, above this menu yo can edit the IDE with you create the project and more options, very easy

2

"IntelliJ IDEA 2022.1.1 (Community Edition)" you have to navigate To Add Exiting Module to same window navigate "File -> New -> Module from Existing Sources" then it will allow you to select pom.xml and then click "Create" button next window then project will be added to your current workspace.

enter image description here

Note :: Who ever switches from Eclipse to Intellij this is the first problem

Sai Ram
  • 63
  • 1
  • 8
1

For people not using maven to build and wanting to add a new project (I am using intellij 14.1.3):

  1. Right click the top level folder in the project view, select new -> Module
  2. Name the module the same name as the project to be added
  3. From the top menu select File->New->Project. Enter the same name as the new module, same folder locations as well.
  4. Open the Project, and wait for intellij to create the project structure.
  5. Close this new project, and open the original project the module was added to in step 2

Depending on your builder, additional steps will be needed to add it to the build process.

For SBT, and in the top level project I modified the Build.scala file to aggregate the new project, and added the project in the SBT projects window. More info on SBT multiproject builds: http://www.scala-sbt.org/0.12.2/docs/Getting-Started/Multi-Project.html

Jenn
  • 884
  • 8
  • 16
  • IntelliJ added support for adding sbt modules to a project and it was working really nice, but it seems to be broken since 2017 versions. You can still add multiple sbt modules but when you refresh, you end up losing all but one. – Nader Ghanbari Nov 25 '18 at 21:00
1

For IntelliJ Idea 2021.3.3 users, The below solution didn't work for me, although I was selecting my project main folder, I've gotten only the main and test folders imported!

Peoject Structure => Modules => Import module

The solution is:

view => tool Windows => Maven => click the + icon => add the project POM.xml file

enter image description here

Ikbel
  • 1,817
  • 1
  • 17
  • 30
1

Try the menu item Window -> Merge All Project Windows

this works on MacOS on IntelliJ 2022.2.3 Community Edition

James Wierzba
  • 16,176
  • 14
  • 79
  • 120
0

you can use import module option which will open it just like eclipse in the same navigator.

SMHasnain
  • 696
  • 4
  • 13
0

Assuming they are under the same folder, click File-Open File or Project-<parent folder>.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 13 '22 at 03:49
-1

I am new to maven and did not understand how I could work with local maven project added through Viktor Nordling's answer and still have a proper dependency in pom.xml file. The answer is simple: intellij first looks at your locally added module and if it doesn't find one it goes to get the project remotely. You can check this by looking at "external libraries" under your project browser when you add or remove maven module.

Hope this helps anyone.

drakonli
  • 2,304
  • 23
  • 29
-1

Intellij by default doesn't provide feature for multiple project in same windows, but mac provides.

For mac 2021(macos ventura):

System settings > Desktop & Dock > Windows & Apps

Enable Prefer tabs when opening documents as Always

enter image description here

Preeti Sharma
  • 112
  • 14
-2

As of release 2019.2, this is as easy as File->Attach Project.

File->Attach Project

See: https://youtrack.jetbrains.com/issue/WEB-7968

Jeremy John
  • 13,686
  • 2
  • 16
  • 16
  • 4
    Are you using the Community Edition or the Ultimate Edition? I am new to Intellij and have only got CE (2019.3.3). This does not have Attach project in that menu. – mike rodent Mar 07 '20 at 17:14
  • AFAICT this is PhpStorm-specific functionality: https://www.jetbrains.com/help/phpstorm/opening-multiple-projects.html?_ga=2.202850905.93262654.1604249137-237327076.1542215793 – Ivan Vergiliev Nov 02 '20 at 09:39
-2

After importing project into IntelliJ, Go to pom.xml of each module -> right click -> Click on Add as Moven Project. It will add the module as Moven project, do this for all the modules in the Project. Refer this

Java_Arc
  • 1
  • 1