horizon
horizon

Reputation: 503

no mssql-jdbc_auth-8.4.0.x64 in java.library.path | Alternate to copying it manually to java home / bin

I am trying to develop a command line utility which is using "mssql-jdbc_auth-8.4.0.x64.dll"

To build the utility I am using a maven-plugin -

             <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>2.1.0</version>
                <executions>
                    <execution>
                        <id>generate-shell-scripts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                        <configuration>
                            <binFileExtensions>
                                <unix>.sh</unix>
                            </binFileExtensions>
                            <platforms>
                                <platform>windows</platform>
                                <platform>unix</platform>
                            </platforms>
                            <repositoryLayout>flat</repositoryLayout>
                            <useWildcardClassPath>true</useWildcardClassPath>
                            <programs>
                                <program>
                                    <mainClass>com.demo.Console</mainClass>
                                    <id>bankLoanCommandLineUtility</id>
                                </program>
                            </programs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

So when you do "maven install" you get a Target/appassembler/bankLoanCommandLineUtility.sh file, which you can run using a powershell or cmd prompt.

Now the problem is, inside target/bin I am generating "mssql-jdbc_auth-8.4.0.x64.dll" using maven like this...

                     <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.microsoft.sqlserver</groupId>
                                <artifactId>mssql-jdbc_auth</artifactId>
                                <version>8.4.0.x64</version>
                                <type>dll</type>
                                <outputDirectory>${project.build.directory}/bin</outputDirectory>
                                <destFileName>mssql-jdbc_auth-8.4.0.x64.dll</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>

This is downloading a copy of DLL in Target/Bin folder.

Now the problem is, when I am executing my command line utility (the .SH file) I am getting below error.

Caused by: java.lang.UnsatisfiedLinkError: no mssql-jdbc_auth-8.4.0.x64 in java.library.path: [T:\BuildTools\Java\jdk-11.0.2\bin, C:\WINDOWS\Sun\Java\bin, C:\WINDOWS\system32, C:\WINDOWS, C:\Program Files (x86)\Microsoft SDKs\Azdata\CLI\wbin, T:\BuildTools\Java\jdk-11.0.2\bin, C:\Program Files\Microsoft MPI\Bin\, C:\WINDOWS\System32\WindowsPowerShell\v1.0\, C:\WINDOWS\system32, C:\WINDOWS, C:\WINDOWS\System32\Wbem, C:\WINDOWS\System32\OpenSSH\, C:\Program Files\Perforce, C:\Program Files\Perforce\, C:\Program Files\dotnet\, C:\Program Files\Microsoft SQL Server\130\Tools\Binn\, T:\BuildTools\Apache\apache-ant-1.10.9\bin, C:\Program Files\apache-maven-3.6.3, C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\, C:\Program Files\Microsoft SQL Server\150\DTS\Binn\, C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\, C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn\, C:\Program Files\Microsoft SQL Server\150\Tools\Binn\, C:\Program Files\Azure Data Studio\bin, C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\, C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\, C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\, C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\, C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\, T:\BuildTools\Java\jdk-11.0.2, C:\Program Files\nodejs\, C:\ProgramData\chocolatey\bin, C:\Program Files\PowerShell\7\, C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps, C:\Program Files\Perforce\Server, C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code\bin, C:\Users\Administrator\.dotnet\tools, C:\Users\Administrator\AppData\Roaming\npm, .]

Clearly from error message, the tool is not loading the DLL from Target/Bin instead looking for Paths in System for DLL (Eg, Java home path/bin and like wise).

I can manually place the DLL to path and everything is good and dandy, but I can not and I should not.

Now one more workaround, I can give

<outputDirectory>${java.home}/bin</outputDirectory>

intead of

<outputDirectory>${project.build.directory}/bin</outputDirectory>

This will take DLL to java.home/bin after I do maven install and again everything works BUT I can not do this, because I have to share only the Target Folder to other team and they will run the tool (they can not do "maven install" in order to move that DLL to java home/bin folder)

Is there a way I can use POM to load DLL or load DLL from main() when DLL is inside target. Or any other approach? Please let me know.

Upvotes: 2

Views: 372

Answers (1)

SharadxDutta
SharadxDutta

Reputation: 1128

${project.build.directory}/bin change this to

${project.build.directory}/appassembler/bin

Keep .sh and dll in same folder, it will work just fine. ;)

Upvotes: 1

Related Questions