# Best practice to package java and native library

**URL:** <https://discuss.gradle.org/t/best-practice-to-package-java-and-native-library/41307>\
**Category:** Help/Discuss\
**Created:** [October 29, 2021, 8:14am UTC](https://discuss.gradle.org/t/best-practice-to-package-java-and-native-library/41307 "2021-10-29T08:14:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![geller1a](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@geller1a](https://discuss.gradle.org/u/geller1a)\
**Post date:** [October 29, 2021, 8:14am UTC](https://discuss.gradle.org/t/best-practice-to-package-java-and-native-library/41307/1 "2021-10-29T08:14:23Z")

</div>

Hi,

short question on the following use case:  
I would like to package and distribute a Java application, that needs a native (C++) library as well.  
The build process is not on focus, but packaging and mainly setting of java.library.path.

**Setup (for Linux):**  
Std-gradle project using application plugin. The native library is included in the distribution by:

```gradle
distributions {
     main {
         contents {
             into ('lib') {
               from ("farAway/libNativeVersion.so");  
             }
         }
     }
 }

```

This results in a tarball, that included jars, start script as well as native library (in the lib folder).

**Challenge/ Question:**  
By distributing the tarball, the start script could easily point to a relative directory (=\> ‘lib’) in order to define -Djava.library.path, which is needed to locate the native library. Unfortunately, this does only work, if the startscript is started in a predefined location.  
Some people propose to ‘hack’ the startscript, in order to use $APP\_HOME (Hm…).  
(Furthermore variable replacement in the startscript seems to be changed with 7.2)

Is there any guidance to configure a project to find native libraries for a Java application?

Thank you in advance for any comment/ example.  
-Axel  
#native
