Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[help] Problems building module-based app #1265

Closed
denismakogon opened this issue Jul 27, 2019 · 40 comments
Closed

[help] Problems building module-based app #1265

denismakogon opened this issue Jul 27, 2019 · 40 comments

Comments

@denismakogon
Copy link

Hi, I'm kinda unsure where to go.

I have an application that I can safely build and run, see https://github.com/denismakogon/gif-tracker/tree/master.

However, when I switched to modules, I'm facing the compilation problem.
But before that, there are 3 modules, 2 of those have a dependency on java.awt.image.BufferedImage class, one package compiles normally, but the second one that has javacv dependency is not building at all with the following problem:

gif-processor/api.facedetect.com/src/main/java/api/facedetect/com/FaceDetect.java:[96,40] cannot access java.awt.image.BufferedImage
[ERROR]   class file for java.awt.image.BufferedImage not found
[ERROR] 

this is where it fails:

 var frameMat = Java2DFrameUtils.toMat(frame);

my module info looks like:

module api.facedetect.com {

    // core
    requires java.base;
    requires java.desktop;

    // 3rd-party
    requires org.bytedeco.opencv.platform;
    requires org.bytedeco.javacv.platform;

    // local modules
    requires api.gif.com;

    exports api.facedetect.com;
}

could that be possible that java.desktop module wasn't included somewhere in a lib?

Module-based application you may find here: https://github.com/denismakogon/gif-tracker/tree/java-modules

Any recommendation appreciated.

@saudet
Copy link
Member

saudet commented Jul 28, 2019

Yes, it sounds like java.desktop is needed. Could you confirm?

@denismakogon
Copy link
Author

I checked the module definition here https://github.com/bytedeco/javacv/blob/master/src/main/java9/module-info.java, first, it seems like the only place where this definition exists (which makes me think that better modularity is a lot like appreciated), there's no java.desktop dependency.

@saudet
Copy link
Member

saudet commented Jul 29, 2019

I've updated the module-info.java file with that entry.
Could you give it a try with the snapshots?
http://bytedeco.org/builds/

@denismakogon
Copy link
Author

Can confirm, 1.5.2-SNAPSHOT works, can build modules successfully:

[INFO] gif-processor ...................................... SUCCESS [  0.005 s]
[INFO] api.gif.com ........................................ SUCCESS [  1.071 s]
[INFO] api.facedetect.com ................................. SUCCESS [02:30 min]
[INFO] main.gif.app ....................................... SUCCESS [  0.735 s]
[INFO] ------------------------------------------------------------------------

thanks!

@saudet
Copy link
Member

saudet commented Jul 29, 2019 via email

@denismakogon
Copy link
Author

There's one more thing.
Assume that I'd like to build JARs for the target platform, let's say MacOS, so in order to obtain the dependencies I do the following:

mvn clean package dependency:copy-dependencies \
    -DincludeScope=runtime \
    -DskipTests=true \
    -Dmdep.prependGroupId=true \
    -DoutputDirectory=target \
    --fail-never \
    -Djavacpp.platform=macosx-x86_64

so, my target folder tree looks like:

target/
├── org.bytedeco.artoolkitplus-2.3.1-1.5.2-SNAPSHOT-macosx-x86_64.jar
├── org.bytedeco.artoolkitplus-2.3.1-1.5.2-SNAPSHOT.jar
├── org.bytedeco.artoolkitplus-platform-2.3.1-1.5.2-SNAPSHOT.jar
├── org.bytedeco.ffmpeg-4.1.4-1.5.2-SNAPSHOT-macosx-x86_64.jar
├── org.bytedeco.ffmpeg-4.1.4-1.5.2-SNAPSHOT.jar
├── org.bytedeco.ffmpeg-platform-4.1.4-1.5.2-SNAPSHOT.jar
├── org.bytedeco.flandmark-1.07-1.5.2-SNAPSHOT-macosx-x86_64.jar
├── org.bytedeco.flandmark-1.07-1.5.2-SNAPSHOT.jar
├── org.bytedeco.flandmark-platform-1.07-1.5.2-SNAPSHOT.jar
├── org.bytedeco.flycapture-2.13.3.31-1.5.2-SNAPSHOT.jar
├── org.bytedeco.flycapture-platform-2.13.3.31-1.5.2-SNAPSHOT.jar
├── org.bytedeco.javacpp-1.5.2-SNAPSHOT.jar
├── org.bytedeco.javacv-1.5.2-SNAPSHOT.jar
├── org.bytedeco.javacv-platform-1.5.2-SNAPSHOT.jar
├── org.bytedeco.leptonica-1.78.0-1.5.2-SNAPSHOT-macosx-x86_64.jar
├── org.bytedeco.leptonica-1.78.0-1.5.2-SNAPSHOT.jar
├── org.bytedeco.leptonica-platform-1.78.0-1.5.2-SNAPSHOT.jar
├── org.bytedeco.libdc1394-2.2.6-1.5.2-SNAPSHOT-macosx-x86_64.jar
├── org.bytedeco.libdc1394-2.2.6-1.5.2-SNAPSHOT.jar
├── org.bytedeco.libdc1394-platform-2.2.6-1.5.2-SNAPSHOT.jar
├── org.bytedeco.libfreenect-0.5.7-1.5.2-SNAPSHOT-macosx-x86_64.jar
├── org.bytedeco.libfreenect-0.5.7-1.5.2-SNAPSHOT.jar
├── org.bytedeco.libfreenect-platform-0.5.7-1.5.2-SNAPSHOT.jar
├── org.bytedeco.libfreenect2-0.2.0-1.5.2-SNAPSHOT-macosx-x86_64.jar
├── org.bytedeco.libfreenect2-0.2.0-1.5.2-SNAPSHOT.jar
├── org.bytedeco.libfreenect2-platform-0.2.0-1.5.2-SNAPSHOT.jar
├── org.bytedeco.librealsense-1.12.1-1.5.2-SNAPSHOT-macosx-x86_64.jar
├── org.bytedeco.librealsense-1.12.1-1.5.2-SNAPSHOT.jar
├── org.bytedeco.librealsense-platform-1.12.1-1.5.2-SNAPSHOT.jar
├── org.bytedeco.openblas-0.3.6-1.5.2-SNAPSHOT-macosx-x86_64.jar
├── org.bytedeco.openblas-0.3.6-1.5.2-SNAPSHOT.jar
├── org.bytedeco.openblas-platform-0.3.6-1.5.2-SNAPSHOT.jar
├── org.bytedeco.opencv-4.1.0-1.5.2-SNAPSHOT-macosx-x86_64.jar
├── org.bytedeco.opencv-4.1.0-1.5.2-SNAPSHOT.jar
├── org.bytedeco.opencv-platform-4.1.0-1.5.2-SNAPSHOT.jar
├── org.bytedeco.tesseract-4.1.0-1.5.2-SNAPSHOT-macosx-x86_64.jar
├── org.bytedeco.tesseract-4.1.0-1.5.2-SNAPSHOT.jar
├── org.bytedeco.tesseract-platform-4.1.0-1.5.2-SNAPSHOT.jar
├── org.bytedeco.videoinput-0.200-1.5.2-SNAPSHOT.jar
└── org.bytedeco.videoinput-platform-0.200-1.5.2-SNAPSHOT.jar

0 directories, 40 files

the module-info of a module that uses javacv looks like:

module api.facedetect.com {

    // core
    requires java.base;
    requires java.desktop;

    // 3rd-party
    requires org.bytedeco.opencv.platform;
    requires org.bytedeco.javacv.platform;

    // local modules
    requires api.gif.com;

    exports api.facedetect.com;
}

My dependency definition looks like:

    <!--3rd-party module dependencies-->
    <dependency>
      <groupId>org.bytedeco</groupId>
      <artifactId>javacv-platform</artifactId>
      <version>1.5.2-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>

    <dependency>
      <groupId>org.bytedeco</groupId>
      <artifactId>opencv-platform</artifactId>
      <version>4.1.0-1.5.2-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>

I can compile and build JARs for my own code with no problem, but when it goes to code execution it more feels like a hell on earth.

Assuming that all necessary javacv/opencv plugins I'm attempting to run my code with the following command:

java -p target/ --module main.app/main.app.Main

unfortunately, it doesn't work (once again I might be missing something). It keeps throwing tons of errors like:

java.lang.module.FindException: Error reading module: main.app/target/org.bytedeco.tesseract-4.1.0-1.5.2-SNAPSHOT.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Package org.bytedeco.teeseract.presets not found in module

moreover, since I use platform flag to identify which JAR's I prefer to obtain, not all javacv dependent modules were resolved successfully because there's there are no Windows, Android, and iOS jars.

So, eventually, I am not able to build to get my application up and running. Therefore I can't build a custom image with jlink because I still not able to figure out what is the minimum set of javacv (and whatever is under its hood) modules packaged as JARs I need to run my app and include them into a custom JRE build.

Unfortunately, as for now, I had to fall back to the use of classpath:

java -cp $(echo main.app/target/*.jar | tr ' ' ':') main.app.Main

If I'm missing something, please give me an advice.

@saudet
Copy link
Member

saudet commented Jul 29, 2019 via email

@denismakogon
Copy link
Author

We can't modify modules, but when I want to build an app for the particular platform I eventually get modules dependencies for other platforms. There are few (or more) modules that depend on Windows, Linux, Android, and iOS at the same time.

Maybe better decoupling could make things easier. Also, I bet there aren't many folks using java modules rather than maven modules, so, in order to showcase how to use javacv in a context of java modules, would be great to create a hello-world sample project that is based on java modules.

@HGuillemet
Copy link
Contributor

HGuillemet commented Jul 30, 2019

To run your application when only the jar of a specific platform is available, do not use the platform jar, but directly the java jar a the native jar for your platform.

In the module-info:

    requires org.bytedeco.opencv;
    requires org.bytedeco.opencv.macosx.x86_64;
    requires org.bytedeco.javacv;
    requires org.bytedeco.javacv.macosx.x86_64

In the pom:

    <dependency>
      <groupId>org.bytedeco</groupId>
      <artifactId>javacv</artifactId>
      <version>1.5.2-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.bytedeco</groupId>
      <artifactId>javacv</artifactId>
      <version>1.5.2-SNAPSHOT</version>
      <classifier>macosx-x86_64</classifier>
    </dependency>

A sample project exists: https://github.com/bytedeco/sample-projects/tree/master/opencv-stitching-jlink
But it uses the platform artifact, so it won't help you much.

@denismakogon
Copy link
Author

@HGuillemet thanks for the reply.

Well, your suggestion is very appreciated. But I fell like taking this path (a recommendation regarding platform-specific modules) is what would make my code un-testable (not just JUnit but an actual attempts to run an app on my laptop) on the non-target platform, so, I'd have to get docker involved (which is fine).

wish there was a simpler and easier way to get things done faster, but still, that you so much for our help.

@denismakogon
Copy link
Author

requires org.bytedeco.javacv.macosx.x86_64;

Failure to find org.bytedeco:javacv:jar:macosx-x86_64:1.5.2-SNAPSHOT in https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of snapshots has elapsed or updates are forced 

repositories configured normally, the rest of packages of javacpp, opencv were resolved normally, except a jar of the org.bytedeco.javacv.macosx.x86_64 module.

@denismakogon
Copy link
Author

It seems like the definition for org.bytedeco.javacv.macosx.x86_64 doesn't exist, at least I wasn't able to find any similar things to this ---> https://github.com/bytedeco/javacpp-presets/blob/079c5119a05fe3426227c6dd521ff05df15a02c6/opencv/platform/pom.xml#L174

@saudet
Copy link
Member

saudet commented Jul 30, 2019

He probably meant requires org.bytedeco.opencv.macosx.x86_64.

@denismakogon
Copy link
Author

He probably meant requires org.bytedeco.opencv.macosx.x86_64

Okay, next showstopper:

Error: Module javafx.graphics not found, required by org.bytedeco.javacv

I run applications in docker or serverless where's basically, no desktop thing available, so javafx or (openjfx) is not available and doesn't seem like needed at all.

What should I do with that? Or is there any path i can take to finally get jlink-ed version of my app?

@saudet
Copy link
Member

saudet commented Jul 30, 2019

That comes with JavaFX, and it's already a dependency here:
https://github.com/bytedeco/javacv/blob/master/pom.xml#L318

@denismakogon
Copy link
Author

If javafx dependency is there, then why it's not picked up? Sorry, first time facing with javafx.

@denismakogon
Copy link
Author

Okay, here's what I think. I looked over my code and figured out that the only thing i use from javacv is: org.bytedeco.javacv.Java2DFrameUtils (which is just a bunch of abstractions on top of the org.bytedeco.javacpp and org.bytedeco.opencv).

So, as I've noticed javacv is just an entrypoint to tons of libs (from javacpp presets) which is good, really, but it feels like it's kinda problematic to rely on the whole lib like javacv just for the sake of few interfaces and implementations which is just one *.java file.

I'd like to propose two things (both of those are alternatives to each other):

  • move Java2DFrameUtils and OpenCVFrameConverter class to org.bytedeco.opencv
  • move Java2DFrameUtils and OpenCVFrameConverter and any other opencv-related utils to a separate project/lib with only dependencies to opencv and javacpp.

Any of the following approaches are fine for me and the whole benefit there would in the number of problems I've been facing with and the number of unnecessary dependencies that eventually will go away.

Thoughts?

@saudet
Copy link
Member

saudet commented Jul 30, 2019

Where would you put the interfaces?

@denismakogon
Copy link
Author

Where would you put the interfaces?

Let's say a library: org.bytedeco.opencv.utils or org.bytedeco.opencv_utils. Choose one you like.

@saudet
Copy link
Member

saudet commented Jul 30, 2019

No, I mean, for example, Frame, where would that go?

@denismakogon
Copy link
Author

So, according to source code here's what you need:
Screen Shot 2019-07-30 at 5 26 48 PM

5 files only (maybe some tests as well)

Here's what i get when i (unfortunately) copied those 5 classes:

[INFO] --- maven-jlink-plugin:3.0.0-alpha-2-SNAPSHOT:jlink (default-jlink) @ app.main ---
[INFO] Toolchain in maven-jlink-plugin: jlink [ /Users/denismakogon/java/jdk-14.jdk/Contents/Home/bin/jlink ]
[INFO]  -> module: api.gif.com ( /Users/denismakogon/go/src/github.com/denismakogon/gif-processor/api.gif.com/target/gif.api-1.0.jar )
[INFO]  -> module: main.app ( /Users/denismakogon/go/src/github.com/denismakogon/gif-processor/main.app/target/classes )
[INFO]  -> module: org.bytedeco.opencv.macosx.x86_64 ( /Users/denismakogon/.m2/repository/org/bytedeco/opencv/4.1.0-1.5.2-SNAPSHOT/opencv-4.1.0-1.5.2-SNAPSHOT-macosx-x86_64.jar )
[INFO]  -> module: org.bytedeco.opencv ( /Users/denismakogon/.m2/repository/org/bytedeco/opencv/4.1.0-1.5.2-SNAPSHOT/opencv-4.1.0-1.5.2-SNAPSHOT.jar )
[INFO]  -> module: api.facedetect.com ( /Users/denismakogon/go/src/github.com/denismakogon/gif-processor/api.facedetect.com/target/facedetect.api-1.0.jar )
[INFO]  -> module: org.bytedeco.openblas ( /Users/denismakogon/.m2/repository/org/bytedeco/openblas/0.3.6-1.5.2-SNAPSHOT/openblas-0.3.6-1.5.2-SNAPSHOT.jar )
[INFO]  -> module: org.bytedeco.javacpp ( /Users/denismakogon/.m2/repository/org/bytedeco/javacpp/1.5.2-SNAPSHOT/javacpp-1.5.2-SNAPSHOT.jar )
[INFO] 
[INFO] api.facedetect.com file:///Users/denismakogon/go/src/github.com/denismakogon/gif-processor/api.facedetect.com/target/facedetect.api-1.0.jar
[INFO] api.gif.com file:///Users/denismakogon/go/src/github.com/denismakogon/gif-processor/api.gif.com/target/gif.api-1.0.jar
[INFO] java.base file:///Users/denismakogon/java/jdk-14.jdk/Contents/Home/jmods/java.base.jmod
[INFO] java.datatransfer file:///Users/denismakogon/java/jdk-14.jdk/Contents/Home/jmods/java.datatransfer.jmod
[INFO] java.desktop file:///Users/denismakogon/java/jdk-14.jdk/Contents/Home/jmods/java.desktop.jmod
[INFO] java.prefs file:///Users/denismakogon/java/jdk-14.jdk/Contents/Home/jmods/java.prefs.jmod
[INFO] java.xml file:///Users/denismakogon/java/jdk-14.jdk/Contents/Home/jmods/java.xml.jmod
[INFO] jdk.unsupported file:///Users/denismakogon/java/jdk-14.jdk/Contents/Home/jmods/jdk.unsupported.jmod
[INFO] main.app file:///Users/denismakogon/go/src/github.com/denismakogon/gif-processor/main.app/target/classes/
[INFO] org.bytedeco.javacpp file:///Users/denismakogon/.m2/repository/org/bytedeco/javacpp/1.5.2-SNAPSHOT/javacpp-1.5.2-SNAPSHOT.jar
[INFO] org.bytedeco.openblas file:///Users/denismakogon/.m2/repository/org/bytedeco/openblas/0.3.6-1.5.2-SNAPSHOT/openblas-0.3.6-1.5.2-SNAPSHOT.jar
[INFO] org.bytedeco.opencv file:///Users/denismakogon/.m2/repository/org/bytedeco/opencv/4.1.0-1.5.2-SNAPSHOT/opencv-4.1.0-1.5.2-SNAPSHOT.jar
[INFO] org.bytedeco.opencv.macosx.x86_64 file:///Users/denismakogon/.m2/repository/org/bytedeco/opencv/4.1.0-1.5.2-SNAPSHOT/opencv-4.1.0-1.5.2-SNAPSHOT-macosx-x86_64.jar
[INFO] 
[INFO] Providers:
[INFO]   java.desktop provides java.net.ContentHandlerFactory used by java.base
[INFO]   java.base provides java.nio.file.spi.FileSystemProvider used by java.base
[INFO]   java.desktop provides javax.print.PrintServiceLookup used by java.desktop
[INFO]   java.desktop provides javax.print.StreamPrintServiceFactory used by java.desktop
[INFO]   java.desktop provides javax.sound.midi.spi.MidiDeviceProvider used by java.desktop
[INFO]   java.desktop provides javax.sound.midi.spi.MidiFileReader used by java.desktop
[INFO]   java.desktop provides javax.sound.midi.spi.MidiFileWriter used by java.desktop
[INFO]   java.desktop provides javax.sound.midi.spi.SoundbankReader used by java.desktop
[INFO]   java.desktop provides javax.sound.sampled.spi.AudioFileReader used by java.desktop
[INFO]   java.desktop provides javax.sound.sampled.spi.AudioFileWriter used by java.desktop
[INFO]   java.desktop provides javax.sound.sampled.spi.FormatConversionProvider used by java.desktop
[INFO]   java.desktop provides javax.sound.sampled.spi.MixerProvider used by java.desktop
[INFO]   java.desktop provides sun.datatransfer.DesktopDatatransferService used by java.datatransfer
[INFO] Building zip: /Users/denismakogon/go/src/github.com/denismakogon/gif-processor/main.app/target/app.main-1.0.zip
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:copy-dependencies (default-cli) @ app.main ---
[INFO] Copying openblas-0.3.6-1.5.2-SNAPSHOT.jar to /Users/denismakogon/go/src/github.com/denismakogon/gif-processor/target/org.bytedeco.openblas-0.3.6-1.5.2-SNAPSHOT.jar
[INFO] Copying facedetect.api-1.0.jar to /Users/denismakogon/go/src/github.com/denismakogon/gif-processor/target/com.giphy.facedetect.api-1.0.jar
[INFO] Copying opencv-4.1.0-1.5.2-SNAPSHOT-macosx-x86_64.jar to /Users/denismakogon/go/src/github.com/denismakogon/gif-processor/target/org.bytedeco.opencv-4.1.0-1.5.2-SNAPSHOT-macosx-x86_64.jar
[INFO] Copying opencv-4.1.0-1.5.2-SNAPSHOT.jar to /Users/denismakogon/go/src/github.com/denismakogon/gif-processor/target/org.bytedeco.opencv-4.1.0-1.5.2-SNAPSHOT.jar
[INFO] Copying javacpp-1.5.2-SNAPSHOT.jar to /Users/denismakogon/go/src/github.com/denismakogon/gif-processor/target/org.bytedeco.javacpp-1.5.2-SNAPSHOT.jar
[INFO] Copying gif.api-1.0.jar to /Users/denismakogon/go/src/github.com/denismakogon/gif-processor/target/com.giphy.gif.api-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for gif-processor 1.0:
[INFO] 
[INFO] gif-processor ...................................... SUCCESS [  0.527 s]
[INFO] api.gif.com ........................................ SUCCESS [  1.274 s]
[INFO] api.facedetect.com ................................. SUCCESS [  2.649 s]
[INFO] app.main ........................................... SUCCESS [  9.186 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  14.272 s
[INFO] Finished at: 2019-07-30T17:32:38+03:00
[INFO] ------------------------------------------------------------------------

boom, jlink worked.

moreover, like you know, javacv brings 20+ jars along with it, but without it the number of actual dependencies went down to 4 jars (openblas, javacpp, opencv, opencv-macosx)

Isn't that great?

oh, yeah, javafx problem disappeared.

@denismakogon
Copy link
Author

No, I mean, for example, Frame, where would that go?

Honestly, based on its imports - javacpp, idiomatically - javacv.utils as a separate package.

@saudet
Copy link
Member

saudet commented Jul 30, 2019

If you're only interested in jlink, I would just create an uber JAR and call it day. IMO, there's nothing else useful about JPMS anyway.

Honestly, based on its imports - javacpp, idiomatically - javacv.utils as a separate package.

So, you want OpenCV to depend on JavaCV and everything that it imports? You're not making any sense.

@denismakogon
Copy link
Author

So, you want OpenCV to depend on JavaCV and everything that it imports?

Um, no. javacv.utils depends on opencv and javacpp, javacv depends on javacv.utils.
It does make sense.

@saudet
Copy link
Member

saudet commented Jul 30, 2019

Um, no. javacv.utils depends on opencv and javacpp, javacv depends on javacv.utils. It does make sense.

Ok, I'll assume you're talking about modules here and not packages. There's obviously a way to separate everything into many more very small modules to work around the limitations of JPMS, but I don't feel it's worth the added complexity or the loss in backward compatibility, since we can already work around the limitations of JPMS in the case of jlink via uber JARs. If you can come up with a simpler solution though, that would be great.

@denismakogon
Copy link
Author

I do understand your concerns, really,

I'll assume you're talking about modules here and not packages

Actually, talking about packages, sorry. I had to admit that your words make a lot of sense, but here I am with my own problems and I really want to build things with javacv (as i've used to with GoCV and Py opencv). So, the blocker, for now, is a huge problem of jlink-ing modules altogether, because of the obvious dependencies problem like javafx that for some reason doesn't link and so on.

So, ideally, I'd like to see a separate maven-consumable jar (package, lib, module - call it as you like) with 5 classes that can be called - javacv.utils with just 2 dependencies: javacpp, opencv.
Meaning, I'd like to have it as a separate thing from the whole javacv.

@saudet
Copy link
Member

saudet commented Jul 30, 2019 via email

@samypr100
Copy link

samypr100 commented Jul 31, 2019

I noticed the poster's error says org.bytedeco.teeseract.presets instead of org.bytedeco.tesseract.presets could this be a typo error on >=1.5.1 build? Doesn't happen on 1.5.

Edit:

Confirmed that one entry module-info.class has teeseract instead of tesseract on >=1.5.1 in org.bytedeco.tesseract (not the platform one). This could the explain issues when using modules.
Before 1.5.1:

...
    exports org.bytedeco.tesseract.global;
    exports org.bytedeco.tesseract;

1.5.1 onwards:

...
    exports org.bytedeco.tesseract.global;
    exports org.bytedeco.teeseract.presets;
    exports org.bytedeco.tesseract;

Edit 2:

Just noticed this seems to be fixed on commit: bytedeco/javacpp-presets@8c5ca2b probably, likely nvm, but 1.5.1 build will be broken if using module stuff.

@denismakogon
Copy link
Author

@saudet

Or could you explain why this doesn't work for you?

First, my use cases are driven by serverless development, I have pretty strict constraints on the size of the final runtime image where JDK + uber jar doesn't fit. So, I refactored my code into a set of modules that would eventually make it to jlink-ed runtime.
Just to compare numbers:

  • uber jar + JDK on OL 7 = 825Mb
  • jlink-ed runtime + necessary libs on OL7 = ~300Mb

In serverless, we pay for the size and for the execution time (that includes the time for obtaining a docker image with an application's code).

So, that's why I want to get better granularity from the dependencies I have, as I stated before, my code depends on javacv (and all of its dependencies) only because of 1 class (subsequently, pluf 4 more classes) that doesn't really have to be part of javacv because it does all the work for opencv Frame/BufferedImage/Mat conversion, meaning that it might become a separate distribution unit that I can consume through maven without involving javacv and all of its dependencies.

@saudet
Copy link
Member

saudet commented Jul 31, 2019

We can still use jlink with an uber JAR, get the same end result, with the exact same size. I still don't understand the problem. It just sounds like you want to transfer to me your work. You'll need to make a better case. :)

@denismakogon
Copy link
Author

get the same end result, with the exact same size

I'm really sorry to say this but that's not true, tested, when I bring back javacv as a dependency I end up having tons of platform-specific jars that I would never use in my application.

It just sounds like you want to transfer to me your work

No, I really don't. What I don't understand is for what reason in any programming language and a library I need to pull tons of redundant things just because of few classes. At this moment, the code coupling is just unacceptable. In almost all cases, it would be better to make a project more granular because that makes things more flexible and less problematic.

You have all libs being separate while JavaCV is a glue-code that makes things friendlier.
So, tell me, why there is no reason in building yet another package/module/dependency that will just contain necessary utils classes?

@HGuillemet
Copy link
Contributor

I guess Samuel suggests to use some kind of minimization of the uber-jar (using option minimizeJar from maven shade plugin, or proguard , or maybe other tools). The Uber jar needs then to be modularized (with moditect or whatever). Maybe there
Is already a tool to do both. I haven't tested this solution myself with javacpp. I don't know if there will be issues with the loader.

@saudet
Copy link
Member

saudet commented Jul 31, 2019

@denismakogon Tell you what: Fork JavaCV, maintain it however you want, maybe others will start using it, and if in a year or two you're still there, then we can discuss merging your changes and you can start maintaining them here. Until then, I have better things to do than to add unnecessary complexity.

@saudet
Copy link
Member

saudet commented Aug 1, 2019

@HGuillemet We don't even need to modularize the uber JAR, here's an example of that:
https://aws.amazon.com/blogs/opensource/using-graalvm-build-minimal-docker-images-java-applications/
The JAR doesn't get turned into an image, and we don't get the little launch scripts, but that's about it. Besides, GraalVM can do native images, so that's probably worth more time exploring than jlink.

@denismakogon
Copy link
Author

@saudet graalvm is a separate thing, the idea and a task to use native java tools and jlink for shrinking the size of the runtime.

Tell you what: Fork JavaCV, maintain it however you want, maybe others will start using it, and if in a year or two you're still there, then we can discuss merging your changes and you can start maintaining them here

Thank you for such a detailed answer, however, I'd rather not. If you don't see any value and not willing to play fair OSS where you have a user that asks for better modularity and you answer "i don't want to do your work".

Thank you for your time.

@saudet saudet reopened this Aug 2, 2019
@saudet
Copy link
Member

saudet commented Aug 2, 2019

Thank you for such a detailed answer, however, I'd rather not. If you don't see any value and not willing to play fair OSS where you have a user that asks for better modularity and you answer "i don't want to do your work".

Now you're starting to get it. That's what open source is all about! You're the only user that has ever asked for this. I do not want to spend my free time working on something that will be useful to only a single person (that is not me). What is so hard to understand about this? If more users come along and ask for it (here for example, so let's keep this issue open), then it makes sense for me to spend time on this. Until then, if you really really really want it, then you do it, or hire someone to do it for you. There is nothing that prevents you!

@saudet
Copy link
Member

saudet commented Aug 2, 2019

Actually, let's just consider this as a duplicate of #1071.

@saudet saudet closed this as completed Aug 2, 2019
@saudet
Copy link
Member

saudet commented Aug 2, 2019

BTW, I do understand the value of splitting everything in modules, but there are also drawbacks. Ever since I've created the "-platform" artifacts, you have no idea how many users are unable to use "javacv-platform" instead of "javacv". And this is just one extra module. Imagine if we have ten of those! Who is going to support them users? I don't personally want to spend all my free time telling people which modules they should be using! If someone else other than me wants to do that job, that's a different question though, but you don't seem like that kind of person @denismakogon.

@saudet
Copy link
Member

saudet commented Aug 7, 2019

@denismakogon Hey, it looks like you were working on this for a blog post?
https://medium.com/@carimura/image-processing-in-java-1e468c92c216
Thanks a lot for that! This will help unearth users who might find this useful.

@denismakogon
Copy link
Author

@saudet Yeah. Both me and Chad were working on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants