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

Project management with javacpp #1479

Open
iexavl opened this issue Feb 27, 2024 · 9 comments
Open

Project management with javacpp #1479

iexavl opened this issue Feb 27, 2024 · 9 comments

Comments

@iexavl
Copy link

iexavl commented Feb 27, 2024

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.

@saudet
Copy link
Member

saudet commented Feb 27, 2024

Please try to use the Maven plugin as per the JavaCPP Presets or Gradle JavaCPP:
https://github.com/bytedeco/gradle-javacpp

@iexavl
Copy link
Author

iexavl commented Feb 28, 2024

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 ?

@saudet
Copy link
Member

saudet commented Feb 29, 2024

@iexavl
Copy link
Author

iexavl commented Mar 1, 2024

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

@saudet
Copy link
Member

saudet commented Mar 1, 2024

You'll need to compile those classes with a call to maven-compiler-plugin before that.

@iexavl
Copy link
Author

iexavl commented Mar 1, 2024

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>

@saudet
Copy link
Member

saudet commented Mar 9, 2024

So, everything works? We can close this?

@saudet
Copy link
Member

saudet commented Mar 9, 2024

No, I guess not. Like I said, try to do like with the presets.

@iexavl
Copy link
Author

iexavl commented Mar 9, 2024

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.

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

2 participants