16

I'm switching to Intellij and trying to do the same thing as in Eclipse. In Eclipse, you can add a project as a dependency in another project (project properties -> "Java Build Path" -> "Projects" -> Click on my library project).

The current situation is that I'm developing a library and I can test the features in another project without building the jar file every time I add new stuff to the library.

I'm trying to achieve this with Intellij but without success (the projects are both imported in Intellij).

How can I do that?

3

4 Answers 4

7

File > Project Structure. Then choose your module, and add any dependency, either Jar, Library or Module:

IntelliJ Screenshot

Larger image here: https://i.sstatic.net/Mr7V7.png

Sign up to request clarification or add additional context in comments.

8 Comments

.. well maybe I'm doing something wrong; but I can only see my current project in the list that displays the modules.
Hmm now, I created a module from the "library" project. Ok I got this working, but is it compulsory to create a module from the other "library" project?
That doesn't work. Yes I can use the library project in mine; but if I add a method or something else, I can't see it in my test project. Any ideas?
Could try just adding the directory where the other code is. Not the nicest thing, but it might work....
This is what I did but it doesnt work either.. I really need this feature. I can't believe its not possible with Intellij but with Eclipse. There's must be a solution...
|
4

From File -> project structure, select Modules. You will be presented with all the added projects. Click a project and from the right hand side select Dependencies tab. This will show you projects that are not imported in red coloured text. HTH

Comments

0

File > Project Structure > Project Settings > Modules

Project Structure

  1. Add the module you want to add as dependency.
  2. Add your module dependency in your project.

If you use Maven you'll see the following message:

Module 'your-module' is imported from Maven. Any changes made in its configuration may be lost after reimporting.

→ Add your project to your pom.xml

If you don't do that, your dependency will be removed each time you reimport/refresh maven projects.

Comments

0

What works for me was:

  • Add dependency on main project in pom.xml (make sure it is as pom in dependency project)
  • Go to the project called on that dependency select maven menu on the right side of the screen and select Lifecycle -> options: clean and then install so It goes to m2 (maven) directory
  • Go back to your main project and compile. maven will find that dependency now that it is installed, If you modify your dependency you will have to repeat the "install" option in maven menu on your dependency project or your main project won't see those changes.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.