aspose file tools*
The moose likes Java in General and the fly likes Problem when executing the LWJGL native library under Java via shell script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem when executing the LWJGL native library under Java via shell script" Watch "Problem when executing the LWJGL native library under Java via shell script" New topic
Author

Problem when executing the LWJGL native library under Java via shell script

riz javaid
Greenhorn

Joined: Feb 15, 2011
Posts: 4

I am running a Java application on the command line bash shell. I have a few JAR files in the directory and a few native libraries. When I run the application using the command line, all works fine. This is the command I use (assuming I change directory to where application is installed):



This works fine and the application starts up as expected. LWJGL native library is loaded in and works fine as expected.

The problem occurs when I try to run this command via the shell using a shell script. Here is my script:




The shell script is in the same directory as the JAR files (the same directory where I ran the Java command above). When I execute the shell script ( sh MyGame.sh ), I get the UnsatisfiedLinkError message:



I don't understand what I am doing wrong. I am executing the exact same command via a shell script and it is not working. I have echoed the Java command I build in the shell script and it is identical to the one I type in. Any ideas, solutions, most welcome. Is there a special way to load libraries when using a shell?

I am running Linux Mint Debian 201012, Linux mint 2.6.32-5-amd64 #1 SMP Thu Nov 25 18:02:11 UTC 2010 x86_64 GNU/Linux. JDK is 1.6.0_22 64-bit. I have 64-bit .so files in the correct place too as the Java command works. Also, file permissions are correct.

Thanks
Riz
Valery Lezhebokov
Ranch Hand

Joined: Jun 12, 2006
Posts: 39
Isn't it something wrong with the quotes here

?


SCJP 1.5, OCE EJB 3.x
riz javaid
Greenhorn

Joined: Feb 15, 2011
Posts: 4

Valery Lezhebokov wrote:Isn't it something wrong with the quotes here

?


Sorry, that was incorrectly copied from my part, I apologise. It should be:



When I run the entire shell script with the correct quote and echo the command I am trying to execute, it all looks fine, but I get UnsatisfiedLinkError.

I am in the correct directory, lwjgl/native/linux folder structure does exist in this directory and the so files and these folders are all executable, have correct permissions.

The reason for the shell script is because I want to launch an application without the user typing this long Java command in when the application is installed.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

Try specifying the absolute path to the lwjgl folder.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
riz javaid
Greenhorn

Joined: Feb 15, 2011
Posts: 4

Rob Spoor wrote:Try specifying the absolute path to the lwjgl folder.


I have tried with absolute path and get the same error.

1) I am running from bash terminal under the /home/riz/MyGame directory (where all JARs are contained and native libs)
2) I run the sh MyGame.sh from the bash terminal.

Could it be that when the shell executes the java command, when the new VM is running, it is not running in the current directory (/home/riz/MyGame)?

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

Definitely. With shell scripts, both on Windows and Linux / Unix, you should never assume it knows which path it's running in, and also never assume that any variables like $PATH (%PATH% in Windows) are set.
riz javaid
Greenhorn

Joined: Feb 15, 2011
Posts: 4

Rob Spoor wrote:Definitely. With shell scripts, both on Windows and Linux / Unix, you should never assume it knows which path it's running in, and also never assume that any variables like $PATH (%PATH% in Windows) are set.


I have solved the problem:

The line:

_VM_PROPERTIES='-Djava.library.path="lwjgl/native/linux"'



should be:

_VM_PROPERTIES=-Djava.library.path="lwjgl/native/linux"



(without the single quotes) and this works fine and starts up all good via the shell script AND if I try on the bash terminal command line.

Thanks for all your help and suggestions.

Riz
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem when executing the LWJGL native library under Java via shell script