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!