Showing posts with label Update POM xml. Show all posts
Showing posts with label Update POM xml. Show all posts

Thursday, November 12, 2015

Steps to setup Java and Maven environment in Bash profile

Follow below steps
1) Start the Terminal app.
2) Open bash profile - 
$ vi ~/.bash_profile
2) Press key 'i' from keyboard to Insert text in bash profile
3) Insert Java and maven environments -
export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
export PATH=$JAVA_HOME:$PATH

4) Press key 'Esc' 
4) Press key ':wq!' to save and quit bash profile
5) Now run source command to refresh
source ~/.bash_profile
6) Verify Java and Maven works fine
Run command - echo $JAVA_HOME
The response should be something like- /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
Run command - mvn --version
The response should be something like-
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T04:57:37-07:00)
Maven home: /usr/local/apache-maven/apache-maven-3.3.3
Java version: 1.8.0_60, vendor: Oracle Corporation
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.11.1", arch: "x86_64", family: "mac"

7) Lastly, run maven project by cd into the Java project directory (enter your project path)- 
cd /Users/[User]/Documents/workspace/Hybrid_TestNG

and run command mvn test
This should run the project successfully. 

Remember, each time you start new session, you will have to source bash profile by running below command - 

source ~/.bash_profile

---------------------------------------------------------------------------------

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