Friday, October 9, 2015

How to have all jars from Maven into Eclipse?

How to have include jars from Maven into Eclipse?


Assuming Project has been imported to eclipse
(If not sure, view previous post at http://selenium2testing.blogspot.com/2015/10/what-is-maven-and-how-to-setup-maven-in.html and
http://selenium2testing.blogspot.com/2015/10/create-mvn-project.html)

Find .M2 repository path (If not sure, View previous post at http://selenium2testing.blogspot.com/)
Copy the .M2 repository path. Ex - /Users/[user]/.m2/repository

Open Eclipse
Import this project
Click on Properties
Click on 'Java Build Path'
Click on Libraries Tab
Click on 'Add Variable' button
Click 'Configure Variables' button
Click New button
Give Name ' M2_REPO' . //Make sure its in caps
Give Repo Path - /Users/[user]/.m2/repository



Run command - mvn eclipse:eclipse is encountering issues with downloading of dependencies

                                                                                                                  

Where is .m2 folder maven repository on mac?

Where is .m2 folder maven repository on mac? 

If you search directly it won't appear so please follow as below steps to see .M2 repository path.
Go-> Find folder ->  type this ~/.m2 and click go
"~/.m2 "

Create MVN Project, Update POM and convert it into Eclipse project

Open terminal / cmd prompt

cd into workspace location  - cd /Users/[username]/Documents/workspace
2. mvn archetype:generate
3. Now hit enter when you will see, 
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 657:  
4. Again hit enter when you see ,
Choose a number: 6: 
5. Enter package name that you are using in your project. ex -
Define value for property 'groupId': : com.selenium.framework.hybrid
6. Enter project name ex -
Define value for property 'artifactId': :  Hybrid_TestNG
7. Enter version 1. ex - Define value for property 'version':  1.0-SNAPSHOT: :  1
8. Just hit enter
Define value for property 'package':  com.selenium.framework.hybrid: : 
9. Hit enter to confirm properties
Confirm properties configuration:
groupId: com.selenium.framework.hybrid
artifactId: Hybrid_TestNG
version: 1
package: com.selenium.framework.hybrid
 Y: : 

You should now see ‘BUILD SUCCESS’ message

Next, Go to Workspace location, Click on the maven project and open pom.xml

Copy paste below dependencies into the pom.xml.. 
Note - Update dependencies versions.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.selenium.framework.hybrid</groupId>
  <artifactId>Hybrid_TestNG</artifactId>
  <version>1</version>
  <packaging>jar</packaging>

  <name>Hybrid_TestNG</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

 <!-- Selenium -->
  <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.47.1</version>
      </dependency>
   <!-- POI -->
   <dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.13</version>
   </dependency>
   <dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.13</version>
   </dependency>
  <dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.13</version>
  </dependency>
  <dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.6.0</version>
</dependency>
<!--  Log4J  -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- JavaMail  -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
  </dependencies>
    <build>
        <plugins>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
              <configuration>
                <suiteXmlFiles>
    <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
                    <!-- Skip the normal tests, we'll run them in the integration-test phase -->
                    <skip>true</skip>               
                 </configuration>               
            </plugin>
            </plugins>
    </build>
 <reporting>
    <plugins>
    <!-- TestNG-xslt related configuration. -->
      <plugin>
        <groupId>org.reportyng</groupId>
        <artifactId>reporty-ng</artifactId>
        <version>1.2</version>
        <configuration>
          <!-- Output directory for the testng xslt report -->
          <outputdir>/target/testng-xslt-report</outputdir>
          <sorttestcaselinks>true</sorttestcaselinks>
          <testdetailsfilter>FAIL,SKIP,PASS,CONF,BY_CLASS</testdetailsfilter>
          <showruntimetotals>true</showruntimetotals>
        </configuration>
      </plugin>
    </plugins>
  </reporting>  
 <pluginRepositories>
    <pluginRepository>
      <id>reporty-ng</id>
      <url>https://github.com/cosminaru/reporty-ng/raw/master/dist/maven</url>
    </pluginRepository>
  </pluginRepositories>
  
</project>

Lastly, to use Maven project as Eclipse project, you need to convert by running following command - 


mvn eclipse:eclipse

Once complete, you should see 'BUILD SUCCESS' message.

You can now, Import this Project in your Eclipse

What is maven and how to setup maven in mac OS X yosemite

MAVEN


Maven is a "build management tool", it is for defining how your .java files get compiled to .class, packaged into .jar (or .war or .ear) files, (pre/post)processed with tools, managing your CLASSPATH, and all others sorts of tasks that are required to build your project. It is similar to Apache Ant or Gradle or Makefiles in C/C++, but it attempts to be completely self-contained in it that you shouldn't need any additional tools or scripts by incorporating other common tasks like downloading & installing necessary libraries etc.
It is also designed to around "build portability" so that you don't get issues that the same code with the same build script works on one computer but not on another one (this is a known issue, we have VMs of Windows 98 machines since we couldn't get some of our Delphi applications compiling anywhere else). Because of this, it is also the best way to work on a project between people who use different IDEs since IDE-generated Ant scripts are hard to import into other IDEs, but all IDEs nowadays understand and support Maven (IntelliJ, Eclipse, and NetBeans). Even if you don't end up liking Maven, it ends up being the point of reference for all other modern builds tools.

Why you should use it
There are three things about Maven that are very nice.
1 Maven will (after you declare which ones you are using) download all the libraries that you use and and the libraries that they they use for you automatically. This is very nice, and makes dealing with lots of libraries ridiculously easy. This lets you avoid "depenendency hell". It is similar to Apache Ant's Ivy.
2 It uses "Convention over Configuration" so that by default you don't need to define the tasks you want to do. You don't need to write a "compile", "test", "package", or "clean" step like you would have to in Ant or a Makefile. Just put the files in the places Maven expects them and it should work off of the bat.
3 Maven also has lots of nice plug-ins that you can install that will handle many routine tasks from generating Java classes from an XSD schema using JAXB to measuring test coverage with Cobertura. Just add them to your pom.xml and they will integrate with everything else you want to do.
The initial learning curve is steep, but (nearly) every professional Java developer uses Maven or wishes they did. You should use Maven on every project although don't be surprised if it takes you a while to get used to it and that sometimes you wish you could just do things manually, since learning something new sometimes hurts. However, once you truly get used to Maven you will find that build management takes almost no time at all.


How to set up MAVEN in MAC OX X

Open terminal and run command - Java -version Enter the same path in Java_Home command
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
To confirm path run this - echo $JAVA_HOME 
# JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home

1. Go to the apache maven website and download the latest stable binary file which is Maven 3.3.3
2. Extract the zip or the tar ball and copy the entire folder to the /usr/local/apache-maven directory.
3. Please create the apache-maven folder under /usr/local directory. So, the final path will look something like this : /usr/local/apache-maven/apache-maven-3.3.3
4. Now, open the terminal and go to the above location by typing the following command: cd /usr/local/apache-maven/apache-maven-3.3.3
5. Now run the following commands in a sequential order:
$export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.3
$export M2=$M2_HOME/bin
$export PATH=$M2:$PATH
6. Now check whether you have the proper JAVA_HOME environment variable set on your machine by running the following command : $echo $JAVA_HOME
It should look something like this:
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
7. You are done with the installation. Now, simply type mvn –version to check if it echoes the details of the maven version installed on your system. You will see the following if the maven is successfully installed.

Apache Maven 3.3.3 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T23:07:52+05:30)
Maven home: /usr/local/apache-maven/apache-maven-3.3.3
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8 

OS name: "mac os x", version: "10.10.5", arch: "x86_64", family: "mac"

cd into Maven project if this doesn't work - cd /Users/[Users]/Documents/workspace/Hybrid_TestNG and try again