'After creating JAR using "maven-jar-plugin" along with "*.Properties"(files), methods from JAR are failing as "*.properties" path is changed

create JAR from maven project, along with all dependable properties files to reuse methods/class from another maven project.

  1. properties files are located into src/main/resource under folder-> ConfigFolder
  2. When JAR is created the path of ConfigFolder changed and below line of code is failing System.getProperty("user.dir")+/src/test/resource/ConfigFolder/Configfilename.Properties

In maven project - *.Properties is being read by below line of code

new FileInputStream(System.getProperty("user.dir")+/src/test/resource/ConfigFolder/Configfilename.Properties")

When Project is converted into Jar using maven-jar-plugin, the hierarchy of Configfilename.Properties changes hence all my methods are failing.

Before converting JAR Folder Hierarchy ProjectName(maven project) |-src/main/java |-src/test/java |-src/test/resource |-ConfigFolder |-Configfilename.Properties |-testSuites |-testng.xml

After converting the into JAR JARNAME-test.jar |-ConfigFolder |-Configfilename.Properties |-testSuties |-testng.xml

As you see after converting the jar the hierarchy got changed and new **FileInputStream(System.getProperty("user.dir")+/src/test/resource/ConfigFolder/Config.Properties") **returns null

requirement is to convert first maven project into JAR and use it into second maven project as first maven project contains n number of reusable methods/class project.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source