joheras / IJ-OpenCV

GNU General Public License v3.0
29 stars 13 forks source link

Issue setting IJ-OpenCV as a dependency #13

Closed LauLauThom closed 4 years ago

LauLauThom commented 5 years ago

Hello, I have written a plugin in Jython that uses the IJ-OpenCV library, now that it comes to distribution I wrapped it into a jar package using the guidelines of this repo so that the dependencies get installed automatically when my plugin is downloaded from an update site.

I have attached the pom file I used to defines IJ-opencv as a dependency for this jar package. I ran mvn -Dimagej.app.directory=/path/to/your/ImageJ.app, to build the jar and update a fresh fiji installation with the dependency. The report of the build is attached.

The problem is when I then open Fiji, an error message shows up claiming that some classes are missing, eventhough I could find the javacpp-1.4.2 and javacv-1.4.2 packages. The error message is also in attachement.

(I had to rename the extension of pom from xml to txt to be able to upload it here) pom.txt Build.txt Error.txt

joheras commented 5 years ago

Hi, it seems that your javacpp-1.4.2 and javacv-1.4.2 packages are not in the correct place, but I am not sure. Could you send me a toy example of what you are trying to do, so I can try to reproduce the problem?

Best, Jónathan

LauLauThom commented 5 years ago

Thanks for the answer, I have made a public repository with the pom.xml and a simple jython script with just the package imports. You can clone it, open a command prompt in the folder containing the pom and type
mvn -Dimagej.app.directory="PATH TO YOUR FIJI.app" Using a fresh fiji installation for instance for this latter path. The build should be successful. Once you open the Fiji it should throw the error above.

joheras commented 5 years ago

Hi,

I was able to reproduce the error and I have tried a couple of things to fix it (compile the jar file together with the dependencies,...); however, I have no idea about what is wrong. I have never used Jython, so I am not sure it this is a problem of IJ-OpenCV or the way of using maven to construct the jar file.

Maybe it is better to write to the ImageJ forum, and if something is wrong with the IJ-OpenCV library I can fix it.

Best, Jónathan

LauLauThom commented 5 years ago

I found out that a jar was missing (opencv-3.4.2-1.4.2.jar highlighted in the screencast). I copied it from my functional Fiji and I dont have the error message anymore at startup. Can you fix that ? image

joheras commented 5 years ago

Hi, I am having problems trying to figure out how to fix this issue. It seems that the dependency is downloaded correctly, but then when it has to copy it to the Fiji repository it shows this: "A newer version for opencv-3.4.2-1.4.2.jar was detected; skipping"

I am not able to find what could be the new version of opencv-3.4.2-1.4.2.jar that is detected. Any idea?

LauLauThom commented 5 years ago

Thanks for the answer I really appreciate the support. I have been advancing a bit on the issue.

I checked the java cv repo. It states that :

The binary archive contains builds for Android, Linux, Mac OS X, and Windows. The JAR files for specific child modules or platforms can also be obtained individually from the Maven Central Repository

So I changed the pom for IJ-OpenCV with the components needed :

I could build IJ-OpenCV like that and setting the dependency for a fresh fiji installation with maven. I found out that OpenCV platform is needed (it contains some dll that are not in opencv-3.4.2.jar) BUT one jar in this dependancy overwrites the opencv-3.4.2.jar. Causing some trouble.

It could be nice to have only the opencv-platform artefact for windows, mac and linux only. I think it is an additional one that overwrites opencv.

You can find the corresponding pom in the following branch

imagejan commented 5 years ago

imagej-maven-plugin recently got replaced by scijava-maven-plugin, but with full backwards compatibility. You could still try if using the now recommended:

mvn -Dscijava.app.directory=...

instead of imagej.app.directory changes anything.

I'm not sure how the copy-jars goal of this plugin handles platform-specific jars though. @ctrueden or @stelfrich might want to comment on this.

LauLauThom commented 5 years ago

Same problem with the scijava-maven-plugin, the opencv-3.4.2-1.4.2.jar is strangely overwritten by some package from opencv platform. I dont really understand why Maven recognize those 2 artifacts (OpenCV and OpenCV-platform) as being the same. I would be curious to see if the problem also happen with Gradle or some other dependency manager.

joheras commented 5 years ago

Sorry for not being able to pay more attention to this issue, I will take a look at it as soon as possible.

imagejan commented 5 years ago

I would be curious to see if the problem also happen with Gradle or some other dependency manager.

I'd suspect that there's nothing wrong with Maven, but the issue is specific to the SciJava plugin (scijava-maven-plugin). Without having dug any deeper, I suppose it could be related to this pattern defining how artifacts and versions are defined in the filenames of jars specific to the SciJava ecosystem:

private final static Pattern versionPattern = Pattern.compile("(.+?)"
  + "(-\\d+(\\.\\d+|\\d{7})+[a-z]?\\d?(-[A-Za-z0-9.]+?|\\.GA)*?)?"
  + "((-(swing|swt|sources|javadoc|native|linux-x86|linux-x86_64|macosx-x86_64|windows-x86|windows-x86_64|android-arm|android-x86|natives-windows|natives-macos|natives-linux))?(\\.jar(-[a-z]*)?))");
ctrueden commented 5 years ago

@Jindil Could you file an issue for this at https://github.com/scijava/scijava-maven-plugin/issues? It is certainly something we should investigate and fix in the scijava-maven-plugin.

imagejan commented 5 years ago

I have written a plugin in Jython that uses the IJ-OpenCV library, now that it comes to distribution

BTW, @Jindil, if you just want to distribute your plugin and dependencies via an update site, you don't need to employ maven: you can set up your local Fiji installation in a way that works, and then use the updater to upload all the required files to your update site. But I guess you know that, right?

LauLauThom commented 5 years ago

@Jindil Could you file an issue for this at https://github.com/scijava/scijava-maven-plugin/issues? It is certainly something we should investigate and fix in the scijava-maven-plugin.

@ctrueden I commented on this similar open issue

@imagejan Thanks for putting some light on the issue. About putting the dependencies on the update site, I think that's what IJ-OpenCV update site is currently doing. But I found the Maven solution cleaner ;)

stelfrich commented 4 years ago

@LauLauThom I have pushed some changes to https://github.com/scijava/scijava-maven-plugin/tree/quickfix-additional-archs. If you are feeling adventurous, you could clone that branch of scijava-maven-plugin and mvn install it locally. Once you have done that, you you should be able to use that version to install your example project with mvn -Dscijava.app.directory="<path>/Fiji.app" -Dscijava-maven-plugin.version="1.1.1-SNAPSHOT"...

This should fix the issue with overwriting of opencv-<version>.jar.

LauLauThom commented 4 years ago

When you say "mvn install" locally you mean I clone it, use the branch you mentioned and from the repo folder of scijiava-maven-plugin I run the mvn install right ? I have a build failure due to some test failing (see attachement). Still the jars are generated so I am not sure it is limiting.

Just wondering how then when I go to the IJ-OpenCv directory and run mvn, the local scijava-maven-plugin is used ? Seems that currently it did not work... CompileIJ-OpenCv.txt CompileScijavaPlugin.txt

ctrueden commented 4 years ago

@LauLauThom If there are failing tests, you can run mvn -DskipTests install instead. Then maybe the instructions above from @stelfrich work?

LauLauThom commented 4 years ago

Hi @ctrueden and @stelfrich, I could compile the new scijava-maven-plugin. I think I had a minor issue with my Maven as described here: I duplicated the mvn.cmd to a mvn.bat and that made it.

For IJ-OpenCV compilation then, the new scijava-maven-plugin is picked but Maven does not like the SNAPSHOT version apparently. Is there a flag to skip this rule ? Error below

[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-rules) @ IJ-OpenCV ---
[INFO] Adding ignore: module-info
[INFO] Adding ignore: META-INF/versions/*/module-info
[INFO] Adding ignore: org.apache.hadoop.yarn.*.package-info
[INFO] Adding ignore: org.apache.spark.unused.UnusedStubClass
[INFO] Adding ignore: org.hibernate.stat.ConcurrentStatisticsImpl
[INFO] Adding ignore: org.junit.runner.Runner
[INFO] Adding ignore: module-info
[WARNING] Rule 1: org.apache.maven.plugins.enforcer.RequirePluginVersions failed with message:
Some plugins are missing valid versions:(LATEST RELEASE SNAPSHOT are not allowed )
org.scijava:scijava-maven-plugin.       The version currently in use is 1.1.1-SNAPSHOT
Plugins need to be versioned!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.084 s
[INFO] Finished at: 2019-10-08T12:20:15+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce (enforce-rules) on project IJ-OpenCV: Some Enforcer rules have failed. 
imagejan commented 4 years ago

@LauLauThom you can run:

mvn -Denforcer.skip
LauLauThom commented 4 years ago

Yeah that works this time ! 🎉 So now I just have to wait till the branch is merged right ? 😊

ctrueden commented 4 years ago

I merged it, and am cutting a new release 1.1.1 of scijava-maven-plugin now.

ctrueden commented 4 years ago

The release failed due to oss.sonatype.org being down/unstable. Will try again in a bit.

ctrueden commented 4 years ago

The scijava-maven-plugin 1.1.1 release is complete now.

ctrueden commented 4 years ago

I'm working to get new pom-scijava releases out the door within the next few days, which will include the new scijava-maven-plugin.