Saturday 23 December 2017

First Eclipse project using Apache Ivy

For installation of IvDE plugin in eclipse refer to this post.

In this post I'll discuss getting started with first project using Ivy.

Steps:
  • Create a new project in eclipse. (In the usual way)
  • Right click on the project in project explorer and then click on new --> other and search for 'ivy file'. Create a new Ivy file. You will get a template file.
Modify the contents of this file so that it looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>

<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
    <info
        organisation="com.test"
        module="Test"
        status="integration">
 </info>
 <dependencies>
    <dependency org="commons-validator" name="commons-validator" rev="1.3.1"/>
 </dependencies>
</ivy-module>


  • This says that we have one dependency on "commons-validator". Search your dependencies on the maven repo and add it to your ivy file.
  • Once you have added all the dependencies, right click on the ivy.xml file and click add Ivy Library. This will add all the dependencies to your project transitively.
  • Create a Test class in com.test package in your project which has following contents:

package com.test;

import org.apache.commons.validator.GenericValidator;

public class Test {

 public static void main(String[] args) {
  if (GenericValidator.isEmail("lavishkothari004@gmail.com")) {
   System.out.println("the entered Email is valid.");
  } else {
   System.out.println("the entered email is not valid");
  }
 }

}


Run the project using Ctrl+F11.

No comments:

Post a Comment