Use Maven to add your favorite Java library to your environment.

** Introduction **

I wanted to maintain my own Java video encoding application a while ago, but when the environment changed, I had to build the external libraries (JavaCV, JavaCPP) again. (Beginner of Windows application, I can't)

That's why I created a Maven environment so that JavaCV can be used easily at any time, so this is a memorandum.

** What is Maven? ** **

I think there are various things, but only the points that are the points in this article are excerpted.

  1. Build information can be entered in the pom.xml file.
  2. The required Java library is automatically downloaded from the Maven repository including the dependent libraries if it is described in pom.xml **

In this article, I will introduce how to describe pom.xml in 2.

About Maven, this article carefully describes the environment construction, so please refer to it if you are interested.

** Added library using Maven. Java CV example **

** Check the installation method on the official website **

Java CV settings

JavaCV is a convenient tool that both OpenCV, an image conversion tool, and FFmpeg, a video encoding tool, can be used in Java.

If you check the Official site, you can see how to describe Maven.

pom.xml


  <dependency>
    <groupId>org.bytedeco</groupId>
    <artifactId>javacv-platform</artifactId>
    <version>1.4.2</version>
  </dependency>

Well, when I read it while wondering if this is all I need, it seems that JavaCPP Presets are also necessary. Actually, this is also essential because it includes the processing related to the main body of OpenCV and FFmpeg.

Java CPP settings

So check Java CPP official website.

pom.xml


  <dependency>
    <groupId>org.bytedeco.javacpp-presets</groupId>
    <artifactId>${moduleName}-platform</artifactId>
    <version>${moduleVersion}-1.4.2</version>
  </dependency>

I also wrote this, okay! What are moduleName and moduleVersion?

Check the supported artifacts in groupId.

JavaCPP contains various artifacts in the Maven repository, so you need to extract the one you want to use. Moreover, it is troublesome to find out that it is necessary to match the version. I'll look it up anyway.

** Check artifact from repository **

When I was googled with javacpp-presets, I found the following repository site. https://mvnrepository.com/ For pinpoint search, use https://mvnrepository.com/artifact/group ID.

If you specify org.bytedeco.javacpp-presets, which is the target of this time, some artifacts will appear like this. I will.

maven.png

This time it was FFmpeg and OpenCV, so check the contents of ffmpeg-platform and opencv-platform. Then, the version information that supports it like this will come out.

maven_version.png

Compared with the official website of Java CPP in the above example, it seems that moduleName ⇒ ffmpeg-platform, module Version ⇒ 4.0.1-1.4.2.

** Final settings **

With reference to the above, dependency was added to pom.xml as follows. As a result of the build, the Java application that the build was creating now works. Yay!

pom.xml


    <dependency>
    	<groupId>org.bytedeco</groupId>
    	<artifactId>javacv-platform</artifactId>
    	<version>1.4.2</version>
    </dependency>
    <dependency>
	    <groupId>org.bytedeco.javacpp-presets</groupId>
	    <artifactId>opencv-platform</artifactId>
	    <version>3.4.2-1.4.2</version>
    </dependency>
    <dependency>
	    <groupId>org.bytedeco.javacpp-presets</groupId>
	    <artifactId>ffmpeg-platform</artifactId>
	    <version>4.0.1-1.4.2</version>
    </dependency>

Finally

How do you find out the version of ** dependency this time? I wrote this article because I wanted to keep the point **.

Looking at it like this, recent development

--Build environment ⇒ Maven and Gradle --Operation tool ⇒ ruby gem, python pip, Linux apt / yum --Operating environment ⇒ Docker

It is common to make the same thing available anytime, anywhere. If you are developing in a closed environment in the company, you may not have many opportunities to touch it, but if you make a new tool by yourself, I would like to actively use these convenient functions.

reference

Maven base: [For super beginners] Maven super introduction First reference article: Installing a convenient development environment called Eclipse + Maven from installation to project creation

Recommended Posts

Use Maven to add your favorite Java library to your environment.
[Java] [Maven3] Summary of how to use Maven3
Introduce Kotlin to your existing Java Maven Project
How to use java non-standard library on IntelliJ IDEA
How to use Truth (assertion library for Java / Android)
[Android Studio] I want to use Maven library on Android
[Java] How to use Map
[Java] How to use Map
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to use string.format
How to use Java Map
[java] Reasons to use static
How to use Java variables
[Java] How to use Optional ①
How to add another project as Maven library with CircleCI and use it for build
Add multi-letter watermark to Java Word
How to use Java HttpClient (Get)
How to use Java HttpClient (Post)
[Java] How to use join method
[Processing × Java] How to use variables
[Java] How to use LinkedHashMap class
[JavaFX] [Java8] How to use GridPane
Welcome to the Java Library Swamp! !!
Add watermark to Java to PDF document
How to use class methods [Java]
[Java] How to use List [ArrayList]
How to use classes in Java?
[Java] Add WordArt to Word document
[Processing × Java] How to use arrays
How to use Java lambda expressions
Add / remove watermark to Java PowerPoint
[Java] How to use Math class
How to use Java enum type
How to add local jar to maven pom.xml
Multilingual Locale in Java How to use Locale
Whether to use Java Comparable or Comparator
Use TMDA to parse IBM Java javacore
[Java] How to add data to List (add, addAll)
[Docker] Building an environment to use Hugo
[Java] How to use the HashMap class
[Easy-to-understand explanation! ] How to use Java instance
[Java] How to use the toString () method
[Java] Use cryptography in the standard library
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
How to use Java classes, definitions, import
[Easy-to-understand explanation! ] How to use Java polymorphism
Add Document to Azure Search Service (Java)
[Processing × Java] How to use the class
How to use Java Scanner class (Note)
[Processing × Java] How to use the function
How to use environment variables in RubyOnRails
Add footnotes to Word documents in Java
[Easy-to-understand explanation! ] How to use ArrayList [Java]
[Java] How to use the Calendar class
[Java] Learn how to use Optional correctly
[Easy-to-understand explanation! ] How to use Java overload
try-catch-finally exception handling How to use java
[Easy-to-understand explanation! ] How to use Java encapsulation