-
Notifications
You must be signed in to change notification settings - Fork 747
Upgrade of presets to 1.5
This is the procedure to transform a pre-1.5 JavaCPP presets to a 1.5 presets, compatible with the Java Platform Module System. All Bytedeco presets have been upgraded to 1.5 and can be used as models for upgrading your own presets.
In the following <PS>
is the name of the presets (e.g. ffmpeg
) and <LIB>
is the name of a native library (e.g. avcodec
). You'll also need to replace bytedeco.org
by your own package.
-
Delete and remove from repository all generated Java files located in
<PS>/src/main/java/org/bytedeco/javacpp
. Beware not to remove not-generated source files that may have been created in this directory. This can be safely done with a command like (using a unix shell):cd <PS>/src/main/java/org/bytedeco/javacpp git rm `grep -l 'DO NOT EDIT THIS FILE' *.java`
remove
git
if your presets is not in git repository. -
Rename the
<PS>/src/main/java/org/bytedeco/javacpp
directory to<PS>/src/main/java/org/bytedeco/<PS>
, and adjust the packages and references in the helper and presets classes accordingly. A search&replace oforg.bytedeco.javacpp.presets
byorg.bytedeco.<PS>.presets
andorg.bytedeco.javacpp.helper
byorg.bytedeco.<PS>.helper
will do. -
Create directory
<PS>/src/java/org/bytedeco/<PS>/<LIB>
for each native library. For presets with a single native library, you can skip this step. -
Create directory
<PS>/src/java/org/bytedeco/<PS>/global
-
In the presets files
<PS>/src/java/org/<PS>/presets/<LIB>.java
: change the value of thetarget
property toorg.bytedeco.<PS>.<LIB>
, or toorg.bytedeco.<PS>
if you skipped step 3. Add after thetarget
property the new propertyglobal
, with valueorg.bytedeco.<PS>.global.<LIB>
. This is the name of the main class that will contain the global members of the library (not enclosed in a C++ class). -
If some helper classes
<PS>/src/main/java/org/bytedeco/helper/<LIB>.java
contain static classes, move these classes out as standalone classes in the directory<PS>/src/main/java/org/bytedeco/<PS>/<LIB>
(or<PS>/src/main/java/org/bytedeco/<PS>
if you skipped step 3). Again, your IDE may help in such task by adapting the packages and changing references. Ensure these files are added to the repository. If the class contains native methods (has astatic { Loader.load(); }
initializer), add the following annotation so that the generator knows to which library they must be linked:@Properties(inherit = org.bytedeco.<PS>.presets.<LIB>.class)
-
Create
<PS>/src/main/java9/module-info.java
containing:module org.bytedeco.<PS> { requires transitive org.bytedeco.javacpp; exports org.bytedeco.<PS>.global; exports org.bytedeco.<PS>.<LIB>; }
Repeat the
exports
line for each native library included in the presets (or omit<LIB>
if you skipped step 3). Also add any exported package that doesn't map a library, if such package exists. Add this file to the repository. -
Modify
<PS>/pom.xml
:- change version to last JavaCPP version, e.g.
1.5.6
- change groupId to
org.bytedeco
- add these 2 plugins:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.moditect</groupId> <artifactId>moditect-maven-plugin</artifactId> </plugin>
- change version to last JavaCPP version, e.g.
-
That's it. Give it a try with a
mvn clean install -pl .,<PS>