1

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.

horizon
  • 453
  • 2
  • 12
  • 1
    Your app is started with the .sh script? If so, you could simply add `-Djava.library.path=` You might also look at using [the JDK](https://technojeeves.com/index.php/aliasjava1/111-making-native-installable-apps-with-java-9) to build a native installer – g00se Jul 16 '21 at 13:18
  • yeah, open cmd prompt, under directory where the .sh is present (bankLoanCommandLineUtility.sh) and hit enter (it takes some parameter being a command line utility but thats another story) – horizon Jul 16 '21 at 13:21
  • dir is Traget/Appassembler – horizon Jul 16 '21 at 13:22
  • Give ^^ a try first – g00se Jul 16 '21 at 13:23
  • @g00se I can not go with this way, because this utility tool (.sh) is like a software, you just need to take and run it with some parameters as argument...I hope you understand what I am trying to say, a software comes as a package, you dont need to get external stuff done inorder to run the software(except you must have java, .net framework isntalled) – horizon Jul 16 '21 at 13:32
  • Can you post it please? – g00se Jul 16 '21 at 13:34
  • @horizon Don't get it, what precisely stops you from adding an parameter inside your shell script? And why a shell script on windows? – Gyro Gearless Jul 16 '21 at 13:58

1 Answers1

1

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

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

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

SharadxDutta
  • 1,058
  • 8
  • 21
  • See if it runs from an entirely different directory. e.g. cd to to C:\ and run it with the path to the .sh file – g00se Jul 16 '21 at 14:07