"Additional operators XML in Linux does not work"

jingram
jingram New Altair Community Member
edited November 5 in Community Q&A
I believe that you cannot load additional operators XML files in linux: the following code works in windows:
String myOperatorsPath = MyInit.class.getResource("/com/mycompany/rapidminer/MyOperators.xml").getPath();
               
logger.info("Attempting to load additional RapidMiner Operators at path {}.", myOperatorsPath); // This will be something like "file:/home/user/my.jar!/com/mycompany/rapidminer/MyOperators.xml"
               
OperatorService.setAdditionalOperatorDescriptors(myOperatorsPath);
               
logger.info("Initialising RapidMiner OperatorService.");

// Note: only need to initialise RapidMiner Operations for this app
OperatorService.init();
But it does not work in Linux because it appears that the operators path is split by RapidMiner's OperaterService according the the Linux file separator ":" and as such the file path above results in two files ("file" and "/home/user/my.jar!/com/mycompany/rapidminer/MyOperators.xml") which are clearly not files :)

OperatorService.init:

String[] additionalOperatorFileNames = additionalOperators.split(File.pathSeparator); // this is ":" on Linux, and ";" on Windows.

for (int i = 0; i < additionalOperatorFileNames.length; i++) {
...
}
I wonder if you could confirm this is a bug and either way provide a solution for loading additional operators from XML file located WITHIN a jar file. Just a reminder that the code does work on Windows, but not linux.

Thanks,

Jon

Answers

  • fischer
    fischer New Altair Community Member
    Hi,

    I can confirm that your code will not work. However, it is a miracle that it works on Windows. The method signature OperatorService.setAdditionalOperatorDescriptors() asks for file names, not URLs, so passing "file:/home/user/my.jar!/com/mycompany/rapidminer/MyOperators.xml" would not work either. Anyway, why do you assume getResource(...).getPath() returns anything that is usable without the rest of the URL? Maybe in your Windows version the class files were not in a Jar but in a file system, so the getPath() actually returned valid file names and it worked by chance.

    I agree that there is no escaping in the mathod you are calling, but adding the escaping would not help either due to the reasons mentioned above. Why don't you just make it an extension, that's much cleaner anyway. Actually I don't remember why the OperatorService.setAdditionalOperatorDescriptors() exists anyway :-)

    Best,
    Simon
  • jingram
    jingram New Altair Community Member
    You're probably right - they are in the file system within my packages, so perhaps through Eclipse they were loaded as files, not from the Jar.

    I'm sure an extension would be cleaner. However, the "additional operators" feature seems very quick and easy. The only steps need are:
    • Write my custom operator (can be in my package as long as it extends Operator).
    • Create my Operators.xml and OperatorsDescription.xml - I actually believe the operator description requirement should be relaxed for quick development and plugin of operators. In this case, I only need to do step 1.
    • Tell RapidMiner where to find my xml files.
    That's all. I've not looked into extensions and how much code is needed for them though.

    Thanks for the response, Jon.
  • fischer
    fischer New Altair Community Member
    Hi,

    ok, so the only thing you need to do is to use a file rather than a URL.

    In your case, you seem to have a JAR already, so making it an extension, is basically step 3: Tell RapidMiner where to find your xml files. That goes into the manifest.

    Best,
    Simon