1

I have installed Maven 3.0.4 and now want to run already created java project in eclipse 3.3 using Maven. For this, I added eclipse maven plugin and then enabled option "Maven -> Enable Dependency Management" for the project. This action created pom.xml in the same project. To add test files I added source directory.
Now I am very confused as to how can we add jar files in this maven project, although I tried using dependencies but got error of "missing artifacts" while compiling. For eg., one of the jar file in $projectDir/lib folder is "junit-4.8.2.jar" I am using it as "import org.junit.Test;" So should we write:

  <dependency>
    <groupId>org.junit</groupId>
    <artifactId>junit</artifactId>...any unique name
    <version>4.8.2</version>
  </dependency>

If yes, then what else we have to do to let maven pick this jar file while compiling. Also, I am not clear about use of "local repository" which got created in my user account/.m2 folder.

Could anyone please advise..Thanks !!!

Community
  • 1
  • 1
user968813
  • 314
  • 1
  • 4
  • 14

1 Answers1

3

The dependency jars mentioned in the pom file have to reside in specific folders (based on their group id/version numbers) in the .m2/repository directory (usually under the user's home directory) -- also called the local repository. To achieve that, you will need to register your jars with maven to be added to the local repository)

See this article on how to add jars to the local repository and set up the dependencies for the project. Note that you will have to update/re-add the jar to the local repository if it changes (e.g. is coming from one of your own projects, not a 3rd party library you downloaded.)

Alternatively, if you are depending on a 3rd party library, check on the web if that library is already added to some maven repository you can use (so you don't need to add it manually).

Also, if the jar is coming from one of your own projects, it is better to set that up as a maven project as well and add it to your projects dependency that way, so you don't need to update/re-add the resulting jar to the local reposity by hand (compiling that other project via maven will do that for you)

Attila
  • 28,265
  • 3
  • 46
  • 55
  • Thanks @Attila. I followed the steps and manually copied jar files in the .m2 directory. additionally I took help from this link [Add jar into maven](http://stackoverflow.com/questions/364114/can-i-add-jars-to-maven-2-build-classpath-without-installing-them). It works !!! – user968813 May 17 '12 at 14:16