0

At the moment for a project I'm working on I'm using a Maven style project.

I'm using Maven for all my dependencies.

One of my dependencies is a jar file (ExtentReports).

I want to edit an XML file within this jar file. How can I achieve this?

I've seen online about using a ZIP tool, but would it not be overwritten once the program is re-run as I'm using Maven? Or is my concept of Maven wrong?

Thanks in advance.

EDIT:

<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
  <configuration>
    <!-- report theme -->
    <!-- standard, dark -->
    <theme>standard</theme>

I want to change the above to

<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
  <configuration>
    <!-- report theme -->
    <!-- standard, dark -->
    <theme>dark</theme>
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
colin
  • 603
  • 1
  • 7
  • 21
  • 1
    you want to edit an XML file of one of your dependencies, why? you can unpack the dependency and have the XML file placed somewhere in your project, then work on it as a copy, would that suit your requirements? – A_Di-Matteo Jun 03 '16 at 09:12
  • I presume it might? Would you have any articles to show how this can be achieved? Thanks @A.DiMatteo – colin Jun 03 '16 at 09:41
  • 1
    to be more clear, do you need this edited XML for some logic or you need to override the library's one with your edited one? Does at runtime this library need to read the edit and ignore its own copy? – A_Di-Matteo Jun 03 '16 at 10:17
  • Theres a line in the XML that I need to change. I don't have an edited version I just want to edit the one thats already there. – colin Jun 03 '16 at 10:25
  • Possible duplicate of [maven overwrite resource file in dependency](http://stackoverflow.com/questions/8085996/maven-overwrite-resource-file-in-dependency) – Gerold Broser Jun 03 '16 at 10:45
  • BTW, did you add this depencency `jar` to your Maven repo(s)? If not see [maven-install-plugin:install-file](https://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html) and [maven-deploy-plugin:deploy-file](https://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html). – Gerold Broser Jun 03 '16 at 10:53
  • No Not install-file etc. use build-helper-maven-plugin to attach the appropriate file. – khmarbaise Jun 03 '16 at 12:43
  • I edited the question to maybe give a clearer insight to what I want to achieve. – colin Jun 03 '16 at 13:40

1 Answers1

1

That is not the correct approach as the settings part of the ExtentReports.jar are default and any other settings that you load during runtime overwrite default ones.

See here: http://extentreports.relevantcodes.com/java/#configuration

Copy the entire configuration block from the above link, place it inside an XML file and put it in your source. After that, simply use one of the methods below to load the XML when your project starts:

// file location: "C:\HelloWorld\extent-config.xml"
loadConfig(new File("C:\HelloWorld\extent-config.xml"));


// loadConfig(Class clazz, String fileName);
// clazz: com.relevantcodes.extentreports.ExtentReports
// packagePath of clazz: com/relevantcodes/extentreports
// final path: com/relevantcodes/extentreports/extent-config.xml
loadConfig(ExtentReports.class, "extent-config.xml");


// loadConfig(Class clazz, String basePackagePath, String fileName;
// clazz: com.relevantcodes.extentreports.ExtentReports
//  packagePath of clazz: com/relevantcodes/extentreports
// basePackagePath: "resources"
// final path: com/relevantcodes/extentreports/resources/extent-config.xml
loadConfig(ExtentReports.class, "resources", "extent-config.xml");
Anshoo
  • 725
  • 5
  • 10