Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

Tuesday, July 16, 2013

Install a JAR to local maven repository

When dependency jars are not available in maven central repository you have to install it to your local repository or you can provide it using system path. Using following command you can send your dependency jar to your local m2 repository.

mvn install:install-file -Dfile=<path/to/your/dependecy/jar> -DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version> -Dpackaging=jar


Eg:Let's get google gson library as an example, This is already available in maven repository but here we are going to manually install it to our local m2 repo. Assume i have downloaded gson-2.2.4.jar to my desktop

         <dependency>
             <groupId>com.google.code.gson</groupId>
             <artifactId>gson</artifactId>
             <version>2.2.4</version>
         </dependency>

mvn install:install-file -Dfile=/home/shameera/Desktop/gson-2.2.4.jar -DgroupId=com.google.code.gson -DartifactId=gson -Dversion=2.2.4 -Dpackaging=jar

You will see similar output like below.

[INFO] Scanning for projects...
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ standalone-pom ---
[INFO] Installing /home/shameera/Desktop/gson-2.2.4.jar to /home/shameera/.m2/repository/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------


As same as you can install your own jars to local maven repo and refer it in different project.





Friday, September 28, 2012

Maven doesn't run all tests but print build success message and quit

When i am writing an end-to-end test to Apache Axis2 JSON support(End-to-end means it up a Axis2 server and deploy a service which is created on a fly, on it and test with that service and stop Axis2 server end of tests). Here i faced a problem that when i run the test using maven(mvn test) it runs isolation test(test particular functions of a class) upto my end-to-end test. it print build success message in terminal console and quit.

OOPs what happened to other isolation tests :( . then i debug the code and see are there any test failure in my end-to-end test but, believe me end-to-end test pass all tests and successfully execute @After method which is tearDown() method too. After that it return build success message and quit. How i can find a error when it says build success :) . Finally i found the solution for that. solution is add <forkMode>pertest</forkMode> to the suirefire maven test plugin. Then every things ok , it runs all test including above end-to-end.

Thursday, July 5, 2012

Add eclipse jdt core dependency and third party repository

Artifact details
Group: org.eclipse.jdt
Artifact id: core
Version: 3.4.2.v_883_R34x
Version type: Unknown
Repository: JBoss Thirdparty Releases
Repository url: https://repository.jboss.org/nexus/content/repositories/thirdparty-releases


Maven dependency



Maven repository



add this maven repository to your pom file as

<project>
.........
  <repositories>
        <repository>
         ......
      </repository>
    </repositories>
</project>

Saturday, January 28, 2012

Configure pom.xml to use JAVA_HOME to compile a mavan project

If you have a new maven project then you will definitely need to use another jdk version instead of maven default jdk version which is jdk_1.3 to build your maven project. Here I point you out how to use your JAVA_HOME to build your maven project. It is simple what you need is just add maven-compiler-plugin to pom.xml file of your project as i have mentioned below.

I have exported jdk_1.6.0_30 as my JAVA_HOME variable in .bashrc file and have set PATH bin.

i.e : export JAVA_HOME=/path/to/jdk
export PATH=$JAVA_HOME/bin:$PATH 

Here is how i uses my jdk_1.6 to build my maven project.

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <executable>${java.home}/bin</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>

Friday, January 20, 2012

How to Install Maven2/Maven3 in ubuntu

Maven is a java building tool which can uses for compile,run test, install, etc.. Today I'm going to tell you how to install maven2/maven3 in ubuntu by manually and by apt-get package manager.

Install Maven2 manually

1. First you need to download maven 2.2.1 binary file.
2.Extract downloaded binary file to a directory where you like to keep maven . Let's say you created a directory call "maven-2.2.1" in your home directory.
3. Now you need to set maven classpath in ".bashrc" file.
         i. Open your terminal and type "cd" to go to home directory where .bashrc has located
         ii. Now Type "gedit .bashrc" in your terminal. It will open .bashrc file via gedit.
         iii. Add this line to the end of .bashrc file "export PATH=/home/your_home_directory_name/maven-2.2.1/bin:$PATH" (note: replace your home directory name with "your_home_directory_name", i have added "export PATH=/home/shameera/maven-2.2.1/bin:$PATH"  as my home directory name is "shameera") 

 4. Save and close .bashrc file.

5. Get a new terminal and type "mvn --version" then you will get below line and some other information like java versin and java home. If you need to install oracal(sun) java 1.7 on your machine see my previous post Install Oracle(sun) jdk 1.7 in ubuntu.

          Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)



6. If you get same out put then you have installed maven2 on your machine. NOTE: if you used previous terminal for  this before type "mvn --version" type "source .bashrc".
 
 Install Maven3 using manual

This is same as Maven2 installation. Download apache-maven-3.0.4 instead of maven2 


Install Maven2 using apt-get 

Open a new terminal and type "sudo apt-get install maven2". Then it will ask your password type your password. After that it will ask to install some necessary packages including openjdk if you like to install openjdk on your machine type "y" if not type "n" and use Install Maven2 manuall procedure to install maven2/maven3 on your machine. 

Sample Text

Website counter

Categories