Mule - how to access files in src/main/resources in Java class when running in Studio and Standalone? -


I have a rat CE application that is using XML component to convert to CSV file in XML. My Java class needs access to a flatpak XML file named map.xml - I have placed it in src / main / resources . My Java class is in src / main / java . I am currently accessing the map.xml file in my Java class:

fr = new FileReader ("src / main / resources / map.xml") ;

This works fine in a true studio, but when I try to run this app in standalone genre, I get the following error:

< Code> java Io.FileNotFoundException: src / main / resources / map.xml (no such file or directory)

Is there any way that I can make this file mutually? Work in the studio and standalone? I have also tried fr = new FileReader ("map.xml"); and it fails in the studio.

UPDATE

By combining a reply from Loireer, and some information in the post, I have been able to find a solution to this problem. The Java class has been updated in the following and has worked in both studio and standalone: ​​

  fr = new FileReader (MyClassName.class.getResource ("/ map.xml"). GetPath () );   

UPDATE

How to retire the mule-ap.properties file? If it is similar then it will also work on CloudHeb.

There are several ways to do this:

  1. You can read the resources in the form of this stream, the files under src / main / resources are in your class

    InputStream = this.getClass (). GetResourceAsStream ("Map.xml");

  2. Prepare your transformer as a spring bean in another suggested way and present external map.xml file dependency through spring is .

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -