Skip to content

Commit 0229b41

Browse files
committed
Updated to use automatic code generation
1 parent 91918e3 commit 0229b41

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

pom.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<plugin>
2828
<groupId>org.bytedeco</groupId>
2929
<artifactId>javacpp</artifactId>
30+
<version>1.4.1</version>
3031
<configuration>
3132
<classPath>${project.build.outputDirectory}</classPath>
3233
<includePaths>
@@ -43,6 +44,19 @@
4344
</compilerOptions>
4445
</configuration>
4546
<executions>
47+
<execution>
48+
<id>javacpp.parser</id>
49+
<phase>generate-sources</phase>
50+
<goals>
51+
<goal>build</goal>
52+
</goals>
53+
<configuration>
54+
<skip>false</skip>
55+
<outputDirectory>${project.build.sourceDirectory}</outputDirectory>
56+
<!-- Change to your package name -->
57+
<classOrPackageName>pl.krzysg.MyCppLibConfig.*</classOrPackageName>
58+
</configuration>
59+
</execution>
4660
<execution>
4761
<id>process-classes</id>
4862
<phase>compile</phase>
@@ -51,7 +65,7 @@
5165
</goals>
5266
<configuration>
5367
<classOrPackageNames>
54-
<classOrPackageName>pl.krzysg.MyCppLib</classOrPackageName>
68+
<classOrPackageName>MyCppTarget</classOrPackageName>
5569
</classOrPackageNames>
5670
</configuration>
5771
</execution>

src/main/cpp/pl/krzysg/MyCppLib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace MyCppLib {
1111
std::cout << "Hello world from CPP!" << std::endl;
1212
}
1313

14+
double xyz = 123;
15+
1416
};
1517
}
1618

src/main/java/Main.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import pl.krzysg.MyCppLib.MyCppClass;
21

32
public class Main {
43

54
public static void main(String[] args) {
65
System.out.println("Hello world from Java!");
7-
8-
MyCppClass x = new MyCppClass();
6+
MyCppTarget.MyCppClass x = new MyCppTarget.MyCppClass();
97
x.foo();
8+
System.out.println(x.xyz());
9+
x.xyz(333);
10+
System.out.println(x.xyz());
1011
}
1112

1213
}

src/main/java/pl/krzysg/MyCppLib.java

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package pl.krzysg;
2+
3+
import org.bytedeco.javacpp.annotation.Namespace;
4+
import org.bytedeco.javacpp.annotation.Platform;
5+
import org.bytedeco.javacpp.annotation.Properties;
6+
import org.bytedeco.javacpp.tools.Info;
7+
import org.bytedeco.javacpp.tools.InfoMap;
8+
import org.bytedeco.javacpp.tools.InfoMapper;
9+
10+
//@Platform(include="MyCppLib.h")
11+
//@Namespace("MyCppLib")
12+
//public class MyCppLib {
13+
// static public class MyCppClass extends Pointer {
14+
// static { Loader.load(); }
15+
// public MyCppClass() { allocate(); }
16+
// private native void allocate();
17+
//
18+
// // to access the member variable directly
19+
// public native void foo();
20+
// }
21+
//}
22+
23+
@Properties(
24+
value = @Platform(include="MyCppLib.h"), target = "MyCppTarget"
25+
)
26+
public class MyCppLibConfig implements InfoMapper {
27+
public void map(InfoMap infoMap) {
28+
// infoMap.put(new Info("MyCppClass").pointerTypes("MyCppClass").define());
29+
}
30+
}

0 commit comments

Comments
 (0)