Hi I am using Maven for Selenium automation tests using Java. I am using Excel Sheet to read data for filling up a registration form. Now It is a normal Maven archetype.
src
--main
--java
--mypackage for coding goes here.
--resources
--data
-- the excel sheet
--test
-- some stuff here under java
currently if I want to read a file I am writing src/main/resources/data/theexcelsheet.xlsx
but when I share this jar, I think this will break and I don’t want this to break if I package this jar.
How do I make it platform or format independent.
I am using APACHE POI Api if you are thinking how I am reading files.
Someone reading gave me idea that I might be able to use MANIFEST files to do this but I am not sure, can someone help?
If you use getResource() to point to your file, the syntax of the path always uses
/to separate the components, never\so you do not have to worry.In general, outside of a jar, for example if you want to save application settings in a folder, you have to use a OS specific separator – you can obtain it this way:
System.out.println("my" + File.separator + "dir");Returns
my\diron Win andmy/diron LinuxOf course, that’s not enough as you cannot use hardcoded paths like the “c:” drive, but you can get the most common paths reading the System class properties, eg:
returns
C:\Users\pieroin Windows7 and/home/pieroin Linux