0

I have created 5 or 6 Java projects in Eclipse by now and will be creating some 20 more projects. I have to add the TestNG library and another library (including some specific jar files) in the project.

Is there any way such that the Eclipse will automatically include both of these libraries at the time of creating every new project?

I don't want to add these libraries on my own by navigating to ADD BUILD PATH -> ADD LIBRARIES.

KhiladiBhaiyya
  • 633
  • 1
  • 14
  • 43

2 Answers2

1

First, you shouldn't use Eclipse dependency management (add libraries manually to build path using Eclipse) if you're already using Maven.

IMO, you should only rely on Maven dependency mangement.

I suggest you to create a Maven parent project that will handle your dependecies used across multiple projects as follow.

Project structure

- maven-parent-project
|-- project-a
|-- project-b
|-- ...

Define Maven parent project

I suggest you used <dependencyManagement> (documentation) to manage the versions of your dependencies.

pom.xml

<project>
    <artifactId>maven-parent-project</artifactId>

    <modules>
        <module>project-a</module>
        <module>project-b</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <!-- Here you can define the versions of your dependencies used accross multiple project -->
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!-- Here you can define the dependencies used accross multiple project -->
    </dependencies>

</project>

Define Maven sub projects

Then, you can define in all your project the maven-parent-project

pom.xml

<project>

    <parent>
        <artifactId>maven-parent-project</artifactId>
        <version>0-SNAPSHOT</version>
        <groupId>group</groupId>
    </parent>

    <artifactId>project-a</artifactId>

    <dependencies>
        <!-- Here you can define the dependencies specific to the project a -->
    </dependencies>

</project>

I hope this will help you.

Mickael
  • 4,458
  • 2
  • 28
  • 40
1

Study about dependency management in Maven. That will solve your requirements. Read this thread to get the jist.

Manmohan_singh
  • 1,776
  • 3
  • 20
  • 29