0

In my class file I have used to read a excel file from my local drive

public static void main(String[] args) throws InterruptedException, IOException {

    driver = new ChromeDriver();
    driver.manage().deleteAllCookies();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    FileInputStream file = new FileInputStream(new File("C:\\Expiration.xlsx"));
    workbook = new XSSFWorkbook(file);
    XSSFSheet sheet = workbook.getSheetAt(0);
    Cell cell;
    Row row = null;
    .....
    .....
}

after that I converted this class file into an jar file, when I executed in my machine its working fine, but executed other machine exception raised, because file not available on that location

clarification let me know how can we avoid this situation?

my expectation jar file along with excel file (package level), while executing file should be read in the package

Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
Prabu
  • 3,550
  • 9
  • 44
  • 85
  • Did you include the excel file in the JAR? – Lasse Meyer Apr 25 '16 at 12:40
  • What you are giving is absolute path of the Excel file. If you want to run your program in another machine, you need to either have that excel file in the same location as it is in your machine or, the excel file should be included in the Jar file and then you can give the relative path of your excel file. – Shreyas Apr 25 '16 at 12:47
  • no, i don't know how to include the excel file in the Jar, please help me how to include the excel file in the jar – Prabu Apr 25 '16 at 12:47
  • Well to add resources to your project, you can use the help from the following links . .[Creating Linked Resources](http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-45.htm) and this too [Add resource folder to your java application](http://stackoverflow.com/questions/27934796/how-do-i-add-a-resources-folder-to-my-java-project-in-eclipse) – Shreyas Apr 25 '16 at 12:51

1 Answers1

0

You can keep the file in your project folder. So you would only need

new File('file.xls');

When you create the JAR it should already be included.

Ashish Patel
  • 163
  • 6