Building a maven project with external JNI libraries - java

I'm developing a program on MacOSx that uses third party jar files that all use JNI to call C functions.
How can I include those on my build path and set the java.library.path to use the external dependencies properly ?
I would like to avoid having to install anything in my maven repository. This is important since I'll have to deploy my program to other linux platforms as well, which already have those third-party jars and C libraries installed somewhere...
For now what I've done is adding my jar dependencies with scope=system and systemPath pointing to the full path of my jar files, but I don't know how to set the os-specific dependencies...
Regards,
Philippe

Could you use:
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
<systemPath>/my/path/to/c_libs_folder/myexecutable.jar</systemPath>
</dependency>

Related

How to connect Java Applocation to JIRA?

I want my java application to communicate with JIRA how can i achieve this functinality. I mean what configuratons are need to add, what are jar files etc ?
You actually don't need Jar files if your java project is using Maven. Just add maven dependency
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${atlassian.product.version}</version>
<scope>provided</scope>
</dependency>
If you are not using maven as build system to your project. Download jar from maven directly and add it to your project.
Follow the documentation https://developer.atlassian.com/server/jira/platform/java-apis/ and start development

How to import Processing libraries into Java application

I am calling Processing functions from Java code.
This works fine for the standard Processing classes, but how to you import other Processing libraries; e.g. gicentre?
I've actually got it working by extracting the jar file from the processing library and then manually installing the artifact into the maven project.
Is there a proper way to do it?
Add this dependancy in your maven pom.xml file.
<!-- mvnrepository.com/artifact/org.processing/core -->
<dependency>
<groupId>org.processing</groupId>
<artifactId>core</artifactId>
<version>2.2.1</version>
</dependency>
Sandip's answer will work for the core Processing library (with the caveat that you should use the latest version, not version 2.2.1), but like you've discovered, gicentre doesn't have a maven repository.
You can download the various gicentre libraries from this page. Each of those libraries comes as a .zip file that contains a .jar file.
Now that you have the .jar file, it's just a matter of adding that .jar to your classpath. How you do that depends on how you've set up your project. The simplest way to do it is to use the command line to compile your project, and then you'd use the -cp argument. You've said you're using Maven, so Googling "maven local jar" will lead to a ton of results, including this one: How to add local jar files to a Maven project?
But note that you don't have to use Maven. You could just set the classpath yourself, either via the command line or via your IDE settings. For simple projects, this can be a better option, especially if Maven is giving you trouble.

How to use this library with Eclipse

I'm trying to use this library https://github.com/axet/vget
I can't seem to figure out how to get a .jar file out of that so I can use it.
Well, you can put the below dependency in your pom.xml if you use Maven.
<dependency>
<groupId>com.github.axet</groupId>
<artifactId>vget</artifactId>
<version>1.1.5</version>
</dependency>
Otherwise, you could download the archive from https://github.com/axet/vget/releases and build it yourself.
If you want the latest (unreleased) version, you'll have to clone the repository on your machine and build it yourself.

Adding a JNI library to the local Maven Repository

I wish to add a JNI library, including its shared object (.so) file to my project using Maven. Unfortunately it is not yet on a public repository so I guess I have to install it myself on my local repository to have it working.
How do I go about including the native part in Maven to be bundled in my project (and eventually exported with the copy-dependencies plugin). This is a standard J2SE app (not a web-app), with packaging .jar?
The library I am trying to add is junixsocket, just in case it helps to know.
It has a .so (native library) component, and the Java .jar component.
I came across maven-nar-plugin which seems to target native builds, but seems to be more oriented towards building a JNI project from code, rather than bundling a 3rd party JNI library, and I can't get to piece the jigsaw puzzle together.
How do I go about:
Installing these in my local repository, having the .jar depending on the .so library.
Including the dependency (on the .jar and .so) in the POM file.
Thanks.
My approach:
Put .so files to repository with platform specific classifier, like this: sqlite3-3.7.9-linux-x86_64.so.
Add .so dependencies for all required platforms:
<dependency>
<groupId>de.ch-werner</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.9</version>
<type>so</type>
<classifier>linux-x86_64</classifier>
</dependency>
Use this maven assembly plugin config to put all native libs into lib/native directory of you dist:
<dependencySet>
<outputDirectory>lib/native</outputDirectory>
<outputFileNameMapping>${artifact.artifactId}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
<unpack>false</unpack>
<useProjectArtifact>false</useProjectArtifact>
<useStrictFiltering>false</useStrictFiltering>
<includes>
<include>*:*:dll:*</include>
<include>*:*:so:*</include>
<include>*:*:jnilib:*</include>
</includes>
</dependencySet>
Use this class to load libs on app startup (planning to change classifier naming to GNU triplets):
CtzJniUtils.loadJniLibsFromStandardPath(Launcher.class, "sqlite3")
I include the .so in the jar and extra the platform specific shared library before loading it. This way it is deployed just like any other jar.
An example of a project where this is done, with multiple .so for different platforms is
https://github.com/peter-lawrey/Java-Thread-Affinity
The main class to look at is https://github.com/peter-lawrey/Java-Thread-Affinity/blob/master/src/main/java/com/higherfrequencytrading/affinity/impl/NativeAffinity.java
As an alternative to unpacking your libraries at runtime, you could store them as jars in Maven but unpack them at build time: http://www.buildanddeploy.com/node/17.
The maven-nativedependencies-plugin plugin will do this for you automatically, as long as you follow their naming convention.

Managing DLL dependencies with Maven

I have a Java program with Maven managing its dependencies. One of those dependency is a JNI wrapper for another program. Maven takes care of the reference to the relevant JAR file, but I'm left messing around with the DLL file myself.
Is there a good way of having Maven handle the DLL as well? Ideally I would like to have the DLL loaded into our local repository like the JAR file.
Did you try something like this:
<dependency>
<groupId>com.foo</groupId>
<artifactId>footron</artifactId>
<version>4.2</version>
<scope>runtime</scope>
<type>dll</type>
</dependency>
You can add them to maven's repository with something like this:
mvn install:install-file -Dfile=footron.dll -DgroupId=com.foo -DartifactId=footron -Dversion=4.2 -Dpackaging=dll -DgeneratePom=true
Haven't done this for DLLs but something like this should work.
I found another solution, which is described in the answer to this question: Using maven with DLL from third party and managing the name of the DLL
Basically, if you put the DLL into a ZIP file, and manage it as a separate dependency, and use the nativedependencies-maven-plugin, then the DLL will get unpacked with the right name.

Categories

Resources