question

Upvotes
Accepted
9 2 0 5

Read Resource file "RDMFieldDictionary" have some problem

In this method

QSConsumer.java
 
public void init()
    {
    	String fieldDictionaryFilename = "../etc/RDM/RDMFieldDictionary";
    	String enumDictionaryFilename = "../etc/RDM/enumtype.def";
    	try 
    	{
    		GenericOMMParser.initializeDictionary(fieldDictionaryFilename, enumDictionaryFilename);
    	}
    	catch (DictionaryException ex) 
    	{
    		System.out.println("ERROR: Unable to initialize dictionaries");
    		System.out.println(ex.getMessage());
    		if(ex.getCause() != null)
    			System.err.println(": " + ex.getCause().getMessage());
    		cleanup();
    		return;
    	}

    }

STEP1:

In this source code ,it wants to read RDMFieldDictionary ,

String fieldDictionaryFilename = "../etc/RDM/RDMFieldDictionary";

and i change the code to get the file's path like this

String fieldDictionaryFilename = Thread.currentThread().getContextClassLoader().getResource("rfa/RDMFieldDictionary").getFile();

and i got the result like this

/D:/workspace/xuntou-base-market/xuntou-base-market-facade/target/classes/rfa/RDMFieldDictionary

STEP2:

i start the project user Intellij (a IDE like Eclipse) in my own computer, it runs very well

public class RfaSubscribeThread implements Runnable{
   
    public void run() {

        // Create a demo instance
        QSConsumer demo = new QSConsumer();

        // Startup and initialization
        demo.init();
	//...
    }
}

STEP3:

But when the project has become a Jar File,and start up on the Linux Mechine ,it give me some wrong info like this

ERROR: Unable to initialize dictionaries
ERROR: Check if files file:/usr/local/xuntou/base-market/xuntou-base-market-facade/lib/xuntou-base-market-facade-1.1.9-SNAPSHOT.jar!/rfa/RDMFieldDictionary and file:/usr/local/xuntou/base-market/xuntou-base-market-facade/lib/xuntou-base-market-facade-1.1.9-SNAPSHOT.jar!/rfa/enumtype.def exist and are readable.
: Dictionary file file:/usr/local/xuntou/base-market/xuntou-base-market-facade/lib/xuntou-base-market-facade-1.1.9-SNAPSHOT.jar!/rfa/RDMFieldDictionary does not exist.
RWF: 14.1
RFA: Version = 8.1.0.E2.all, Date = Wed May 02 18:30:50 CST 2018, Jar Path = /usr/local/xuntou/base-market/xuntou-base-market-facade/lib/rfa-1.0.0.jar, Jar Size = 1619345


class com.xuntou.platform.market.rfa.quickstart.QuickStartConsumer.QSConsumer exiting

STEP4:

I seach the internet ,fount in the jar file , use "new File("FilePath")" to get file is not right

i want to change ,but the source code

GenericOMMParser.initializeDictionary(fieldDictionaryFilename, enumDictionaryFilename);

only use "new File('FilePath')" to read the resource file

So, what can i do to avoid the problem.

TIPS: I can't change the source code, it's provided by your company

expect your help, thank you very much!

treprfarfa-apiconsumerrdm
2.png (52.9 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
11.5k 16 7 10

Hello @peng.xiaoliang

Please be informed that this is an expected behavior. The TREP Dictionary files (RDMFieldDictionary and enumtype.def files) are always updated (add new supported fields, fixed dictionary issue, etc) by TR, so the application should place Dictionary files outside the Jar file to let you can easy upgrade them without rebuild the Jar file. You can download the latest version of TREP dictionary file from the Customer Zone https://customers.reuters.com/a/support/technical/softwaredownload/Default.aspx link (Please select Category “MDS – General” and Products “TREP Template Service Pack”).

Please be informed that the RFA API is a feature-completed API. The current strategic API is Elekton Message API (EMA Java API) which is a part of the strategic Elektron SDK family. You can find more detail regarding the EMA Java from the following resources

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

it confused me. I still don't know how to solve this problem. The jar file and source code is provided, the only way to read the dictionary file is use the source code which is provided.

Publish the project to the internet must park the source code to JAR file, but in the jar file ,it can't read the dictionary file . The helper website i can't open it .because of the GFW

Hello @peng.xiaoliang

The dictionary files are not designed to be inside the application Jar file because they are designed to be easy updated by just replacing the files. The application should place dictionary files outside the Jar file and read them from that location.

Upvotes
11.5k 16 7 10

Hello @peng.xiaoliang

I can replicate the issue with the given code. When the application keeps Dictionary files with resources folder and build jar file, the following code cannot access Dictionary files inside jar file:

fieldDictionaryFilename = Thread.currentThread().getContextClassLoader().getResource("etc/RDMFieldDictionary").getFile();
enumDictionaryFilename = Thread.currentThread().getContextClassLoader().getResource("etc/enumtype.def").getFile();

Then I got the following error message when I try to run the jar file.

ERROR: Unable to initialize dictionaries
ERROR: Check if files file:/D:/Project/SRs/AHS_27324/Code/RFA_code/out/artifacts
/RFA_OMM_AHS_27324_jar/RFA_OMM_AHS_27324.jar!/etc/RDMFieldDictionary and file:/D
:/Project/SRs/AHS_27324/Code/RFA_code/out/artifacts/RFA_OMM_AHS_27324_jar/RFA_OM
M_AHS_27324.jar!/etc/enumtype.def exist and are readable.
: Dictionary file file:/D:/Project/SRs/AHS_27324/Code/RFA_code/out/artifacts/RFA
_OMM_AHS_27324_jar/RFA_OMM_AHS_27324.jar!/etc/RDMFieldDictionary does not exist.

I will check this behavior in detail and let you know updates.


ahs.png (12.3 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea