Reputation: 319
I have a jar file that I want to call/run from an SQL stored procedure. To do this, I am using xp_cmdshell.
I haven't created the stored procedure yet but, basically, the content of the stored procedure would be
EXEC master..xp_cmdshell 'java -jar D:\...\...\...\Test_LowerJDK.jar';
I am trying to run this line thru SQL Server Management Studio, just to see if it will work before I create the official stored procedure. However, when I run it, it gives me the following message.
Unable to access jarfile D:.........\Test_LowerJDK.jar
I am not sure why this is happening. I'm guessing its because I wasn't able to go to the specific directory that I want to. If it is, how could I go to the specific directory that I want to so that I can run the jar file in that directory.
FYI I tried running my jar file from the directory where it is saved thru command prompt by
java -jar Test_LowerJDK.jar
Also I tried opening a command prompt in C: and did the following
java -jar D:\...\...\...\Test_LowerJDK.jar
Both work just fine.
Also, I tried displaying my current working directory using xp_cmdshell using,
EXEC master..xp_cmdshell 'dir';
And it seems like my current working directory is
Directory of C:\Windows\system32
I didn't want to paste my jar file in C:\Windows\system32
'cause I might mess things up? I'm not sure that's why I didn't do it.
Upvotes: 0
Views: 594
Reputation: 319
I figured out why I was getting the following message.
Unable to access jarfile D:......\TeamFolder\Test_LowerJDK.jar
The folder that contains Test_LowerJDK.jar is only accessible to a specific User Group. My Administrator account is not a part of the group that can access TeamFolder thus, it cannot access the jarfile.
I tried copying Test_LowerJDK.jar to C:\ and tried the following command.
EXEC master..xp_cmdshell 'java -jar C:\Test_LowerJDK.jar';
It worked well.
The reason I didn't immediately thought about this situation is because using Administrator account I can actually access and go to TeamFolder thru Windows Explorer. I forgot the fact that TeamFolder is actually a local folder in the machine where I logged in as Administrator that's why I can access TeamFolder neatly thru Windows Explorer.
Upvotes: 1