Upload a XML file on a Fiji update site

Following this post about IJ-OpenCV.
Would it be possible to upload a XML file on an update site so that it is distributed with the plugins?
In this particular case, I am talking of this XML file to use the opencv face detection plugin.

I tried to put it in script>Plugins or Jars>Lib but it does not seem to be visible for the updater.

Hi @LThomas,

not sure whether the updater actually picks up XML files, but alternatively, you can package the XML file as a resource in one of your JARs and load it from there. Would that work for you?

Hi, thanks for the answer, I though of this possibility but I am not sure that a script could open it then, because it is not an import statement.
What would be its file path for instance ?

Or is the Ressource some kind of convention with jar files, that offers some workaround to ship extra files ?

Is it as simple as creating a folder ressource in the repo and running maven like usually ?

The resources folder is a convention where to put non-code files, yes. It seems your repo also has the file you mention as a resource. The question now is, where do you want to access it from: From Java code or from a script?

EDIT: Correction – the file is actually in the wrong place and should be in src/main/resources/ijopencv/examples to be picked up by Maven. Apologies!

If you then want to access it from a Class in the same package (examples), you can do MyExampleClass.class.getResource("myXmlFile.xml").

1 Like

I tried to move the XML file to this folder (see repo) but I can’t find it in the resulting jar, eventhough the build mention that the resource was copied.

[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ IJ-OpenCV ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource

Here the resulting jar
IJ-OpenCV-1.2.1.jar (240.5 KB)

If you still want to ship it as a single file instead of a resource in a far file: the file should be picked up if its inside the ./Fiji.app/lib/ folder.

For the other folders, there are some restrictions of the allowed file extensions, defined here:

2 Likes

I just had a look at your JAR, aaaand…

âžś unzip -l IJ-OpenCV-1.2.1.jar | grep xml
   963441  03-28-2019 10:04   ijopencv/examples/haarcascade_frontalface_alt.xml
     4908  02-14-2019 13:05   META-INF/maven/io.github.joheras/IJ-OpenCV/pom.xml

It’s there!

Oh yes indeed my fault ! I overlooked it in the list of class files!

EDIT : And the import works

from ijopencv.examples import FaceDetectionJ_

print FaceDetectionJ_.getResource('haarcascade_frontalface_alt.xml')
print FaceDetectionJ_.getResourceAsStream('haarcascade_frontalface_alt.xml')

Is it possible to access it from a script outside of the class ? Or I just import any class in the package just to access this file ? :sweat_smile:
Indeed this FaceDetectionJ class is an example, to help get you started to make your own script…

You can import any class in the package and use that for getResource. The way getResource works is you can either give it a relative path (relative to the class), such as in FaceDetectionJ_.getResource('haarcascade_frontalface_alt.xml'), or you can give an absolute path, e.g. FaceDetectionJ_.getResource('/my/package/name/has/some/class/haarcascade_frontalface_alt.xml').
Check out the JDK docs on getResource() for the details how this gets resolved by the class loader.

1 Like