Tuesday, January 22, 2013

How to create Maven in-project repository


Pre-requisites :You should have Maven installed on your system.

In my example i am using "sshxcute-1.0" jar file. You can download it from link https://code.google.com/p/sshxcute/"

Follow the below steps :

1. Create a "lib" folder in your java project.(Actually the name does'nt matter you can use "library" instead or whatever you like)

2. Copy the "sshxcute-1.0" jar file in "lib" folder.

3. Open command prompt and navigate to "lib" folder, then execute following command.(In my case 'sshxcute-1.0.jar' file is at "c:\project\src\com\lib" location,so you need to change file locations in below  command accordingly)

mvn deploy:deploy-file -Durl=file:///c:\project\com\src\lib -Dfile=sshxcute-1.0.jar -DgroupId=com.automatethebox -DartifactId=automatethebox -Dpackaging=jar -Dversion=1.0

 Note that you get BUILD SUCCESS on console output after running the command.



4. Now go to your project "lib" directory, and notice that an package "com.automatethebox.apis" is created.This is your in-project maven repositoy.

5. Now Open the project "pom.xml" file

6. Add following dependency in pom.xml file :

<dependencies>
        <dependency>
            <groupId>com.automatethebox</groupId>
            <artifactId>apis</artifactId>
            <version>1.0</version>
        </dependency>
</dependencies>

7. Add following repository in pom.xml file :

<repositories>
        <repository>
            <id>project.local</id>
            <name>project</name>
            <url>file:${project.basedir}/src/com/lib</url>  
        </repository>
</repositories>

NOTE : You need to update this path in url according to your project.

8 .Then refresh the Maven dependencies for the project using your IDE Maven > Reimport option.

All done, now you can use the classes from the Jar file and maintain your Maven project with your in-project Maven repository.

1 comment:

Lalit Narnaulia said...

[img]http://s20.postimg.org/muy9pclm5/how_to_create_maven_in_project.png[/img]

AWS Certified Solutions Architect Associate - AWS Introduction - Questions

All the Best !!! Show Result !! Try Again !! ×