title: Selenium/Java-How to make 'dataProvider' a common function inbetween multiple source folders
body: <p>I have created a project with seperate source folder for each module, say <strong>mod1</strong> &amp; <strong>mod2</strong> and the <strong>src</strong> source folder as common for each source folder.<br>
  And I created <strong>DataProvider_Repository.java</strong> file for reading data from excel sheet. Which now I need to put <strong>Data Provider</strong> in each source folder for accessing it in each testcase(Eg:Registration.java or Del.java).  </p>
  
  <p>How can I make it common &amp; put in <strong>src</strong> folder.
  <strong>DataProvider_Repository.java</strong> contains same code for reading data from excel sheet.</p>
  
  <p><strong>DataProvider_Repository.java</strong></p>
  
  <pre><code>package online;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.lang.reflect.Method;
  import org.apache.poi.ss.usermodel.Row;
  import org.apache.poi.ss.usermodel.Sheet;
  import org.apache.poi.ss.usermodel.Workbook;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  import org.testng.annotations.DataProvider;
  
  public class DataProvider_Repository {
  
       @DataProvider(name="dataProviderRepo")
        public static Object[][] getDataFromDataprovider(Method m) throws IOException{
  
              Object[][] object  = null; 
  
              String filePath = System.getProperty("user.dir")+"\\";
              String fileName = "sample.xlsx";
              String sheetName= "sampleSheet";
  
              File file = new File(filePath+"\\"+fileName);
              FileInputStream inputStream = new FileInputStream(file);
              Workbook wb = new XSSFWorkbook(inputStream);
              Sheet  s = wb.getSheet(sheetName);
  
              //Find number of rows in excel file
              int rowCount = s.getLastRowNum()-s.getFirstRowNum();
              object = new Object[rowCount][6];
  
              for (int i = 0; i &lt; rowCount; i++) {
                  //Loop over all the rows
                  Row row = s.getRow(i+1);
                  int lst = row.getLastCellNum();
  
                  //Create a loop to print cell values in a row
                  for (int j = 0; j &lt; lst; j++) {
                      //Print excel data in console
                      if(row.getCell(j) != null){
                          object[i][j] = row.getCell(j).toString();
                      }
                  }
                  object[i][lst-1] = Integer.toString(i);
              }
              return object;   
          }
  }
  </code></pre>
  
  <p><strong>Registration.java</strong></p>
  
  <pre><code>package online;
  
  import org.testng.annotations.Test;
  
  public class Registration {
  
      @Test(dataProviderClass=DataProvider_Repository.class,dataProvider="dataProviderRepo")
      public void OnlineRegs(String testcaseName,String keyword,String objectName,String objectType,String value, String rowNum) throws Exception {
  
          System.out.println("=======OnlineReg===========");   
  
          //Operations here...    
  
      }
  
  }
  </code></pre>
  
  <p><strong>The folder structure is</strong></p>
  
  <p><a href="https://i.stack.imgur.com/zHc7U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zHc7U.png" alt="enter image description here"></a></p>