Project management with javacpp
iexavl opened this issue · 9 comments
I have been using the javacpp parser for a while and it's been great. One thing that I still don't know how to do though is project management. For now I have been pretty much just winging it by giving the path to the dlls the parser compiles via a VM argument and the rest of the dlls are dealt with in a similar way, but there are some problems with that. For example if I want to compile the whole thing into a jar file and just run it from there(though I'm just not sure how to link with dlls from a jar file anyway). Here is what I have done so far:
I have some c++ header files which are included and linked against in an InfoMapper with a target and a global.
After that's done I open the command prompt and run
java -jar javacpp.jar <path to the info mapper>
and that generates all the .java files corresponding to the classes in the included header files.
After that I run java -jar javacpp.jar <paths to all of the .java files>
, which then compiles all the java files into .class files and also generates native code and compiles that native code to a dll that's found in /windows-x86_64/*.dll (and all the other stuff like *.lib *.exp ...)
At the moment the way this dll is loaded is, as I said before, by giving the absolute path to that dll.
2 things I would like to do to begin with are: moving the .class files to another folder and linking the dll with a relative path.
Also I am using maven.
Please try to use the Maven plugin as per the JavaCPP Presets or Gradle JavaCPP:
https://github.com/bytedeco/gradle-javacpp
Please try to use the Maven plugin as per the JavaCPP Presets or Gradle JavaCPP: https://github.com/bytedeco/gradle-javacpp
I looked through it and some other stuff but to be honest I am still quite confused about how I'm supposed to use it.. I'd like to ask is the plugin able to parse native header files or does that have to be done with the javacpp.jar ?
Sure, please start here: https://github.com/bytedeco/javacpp-presets/wiki/Create-New-Presets
Sure, please start here: https://github.com/bytedeco/javacpp-presets/wiki/Create-New-Presets
yeah I also gave that a read before making a post. Still couldn't quite get it but after giving it another look I decided to take a peek in the pom.xml that's in the base javacpp-presets and I think I found what I needed, but it still doesn't work. More specifically this part seems to not be working:
<execution>
<id>javacpp-parser</id>
<phase>generate-sources</phase>
<goals>
<goal>parse</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/src/gen/java</outputDirectory>
<classOrPackageName>org.example.*</classOrPackageName>
</configuration>
</execution>
In org.example there is a class called Mapper that has a Properties and Platform annotation with an included .hpp header and a target and global. For some reason when I run mvn clean install though, I get this:
[WARNING] No classes found in package org.example
You'll need to compile those classes with a call to maven-compiler-plugin before that.
You'll need to compile those classes with a call to maven-compiler-plugin before that.
Here are all the plugins in my pom.xml, which also includes the maven-compiler-plugin (still doesn't work)
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
</execution>
<execution>
<id>javacpp-parser</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<includes>
<include>${project.build.sourceDirectory}/org/example/*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>1.5.9</version>
<configuration>
<classPath>${project.build.outputDirectory}</classPath>
<includePaths>
<includePath>${project.build.sourceDirectory}/org/example/nat/</includePath>
</includePaths>
<copyLibs>true</copyLibs>
</configuration>
<executions>
<execution>
<id>javacpp-validate</id>
<phase>validate</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<targetDirectories>
<targetDirectory>${project.basedir}/src/gen/java</targetDirectory>
</targetDirectories>
</configuration>
</execution>
<execution>
<id>javacpp-parser</id>
<phase>generate-sources</phase>
<goals>
<goal>parse</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/src/gen/java</outputDirectory>
<classOrPackageName>org.example.*</classOrPackageName>
</configuration>
</execution>
<execution>
<id>javacpp-compiler</id>
<phase>process-classes</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/native/${javacpp.platform.nativeOutputPath}</outputDirectory>
<classOrPackageName>org.example.**</classOrPackageName>
<copyLibs>true</copyLibs>
<copyResources>true</copyResources>
<configDirectory>${project.build.directory}/native/META-INF/native-image/nativeImage/</configDirectory>
</configuration>
</execution>
</executions>
</plugin>
So, everything works? We can close this?
No, I guess not. Like I said, try to do like with the presets.
No, I guess not. Like I said, try to do like with the presets.
I think I may have accidentally deleted the rest of my comment aside from the maven stuff. Yeah it still doesn't work (I actually did have the compiler-plugin before that as well) and also that is pretty much exactly like how the presets do it. I suppose I will take a look again a bit later but at the moment I have ran into another issue.