LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-16-2011, 07:25 AM   #1
rizwanjavaid
LQ Newbie
 
Registered: Feb 2011
Posts: 2

Rep: Reputation: 0
Invoking java from a bash terminal via shell script fails under Mint Debian


I am running a Java application on the command line bash terminal under Mint Debian. I have JDK1.6.0_22 installed 64-bit, and the OS is 64-bit too. I have a few JAR files in the directory and a few native LWJGL libraries. When I run the application using the command line, all works fine.
Lets assume my directory where the files are is called /home/riz/MyGame. I change to that directory and this is the command I use:

Code:
java -classpath MyGame.jar:log4j-1.2.16.jar:jme/jme-colladabinding.jar:jme-audio.jar:jme-awt.jar:jme-collada.jar:jme-editors.jar:jme-effects.jar:jme-font.jar:jme-gamestates.jar:jme-model.jar:jme-ogrexml.jar:jme-scene.jar:jme-swt.jar:jme-terrain.jar:jme.jar:jogl/gluegen-rt.jar:jogl/jogl.jar:jorbis/jorbis-0.0.17.jar:junit/junit-4.1.jar:lwjgl/jinput.jar:lwjgl/lwjgl.jar:lwjgl/lwjgl_util.jar:lwjgl/lwjgl_util_applet.jar:swt/windows/swt.jar:jbullet/jbullet-jme.jar:jbullet/asm-all-3.1.jar:jbullet/jbullet.jar:jbullet/stack-alloc.jar:jbullet/vecmath.jar:trove-2.1.0.jar:sceneMonitor/jmejtree_jme2.jar:sceneMonitor/propertytable.jar:sceneMonitor/scenemonitor_jme2.jar:sceneMonitor/sm_properties_jme2.jar -Djava.library.path="lwjgl/native/linux" -Xmx1024m -Xms768m -ea com.mygame.Main
This works fine and the application starts up as expected. LWJGL native library is loaded in and works fine as expected. Note that I run this command on the bash terminal.

The problem occurs when I try to run this command via a shell script. Here is my script (located under /home/riz/MyGame):

Code:
#!/bin/bash

# Set the minimum and maximum heap sizes
MINIMUM_HEAP_SIZE=768m
MAXIMUM_HEAP_SIZE=1024m

if [ "$MYAPP_JAVA_HOME" = "" ] ; then
    MYAPP_JAVA_HOME=$JAVA_HOME
fi

_JAVA_EXEC="java"
if [ "$MYAPP_JAVA_HOME" != "" ] ; then
    _TMP="$MYAPP_JAVA_HOME/bin/java"
    if [ -f "$_TMP" ] ; then
        if [ -x "$_TMP" ] ; then
            _JAVA_EXEC="$_TMP"
        else
            echo "Warning: $_TMP is not executable"
        fi
    else
        echo "Warning: $_TMP does not exist"
    fi
fi

if ! which "$_JAVA_EXEC" >/dev/null ; then
    echo "Error: No Java environment found"
    exit 1
fi

_MYAPP_CLASSPATH="MyGame.jar:log4j-1.2.16.jar:jme/jme-colladabinding.jar:jme-audio.jar:jme-awt.jar:jme-collada.jar:jme-editors.jar:jme-effects.jar:jme-font.jar:jme-gamestates.jar:jme-model.jar:jme-ogrexml.jar:jme-scene.jar:jme-swt.jar:jme-terrain.jar:jme.jar:jogl/gluegen-rt.jar:jogl/jogl.jar:jorbis/jorbis-0.0.17.jar:junit/junit-4.1.jar:lwjgl/jinput.jar:lwjgl/lwjgl.jar:lwjgl/lwjgl_util.jar:lwjgl/lwjgl_util_applet.jar:swt/windows/swt.jar:jbullet/jbullet-jme.jar:jbullet/asm-all-3.1.jar:jbullet/jbullet.jar:jbullet/stack-alloc.jar:jbullet/vecmath.jar:trove-2.1.0.jar:sceneMonitor/jmejtree_jme2.jar:sceneMonitor/propertytable.jar:sceneMonitor/scenemonitor_jme2.jar:sceneMonitor/sm_properties_jme2.jar"

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

_MYAPP_MAIN_CLASS="com.mygame.Main"

$_JAVA_EXEC -classpath $_MYAPP_CLASSPATH $_VM_PROPERTIES -Xmx${MAXIMUM_HEAP_SIZE} -Xms${MINIMUM_HEAP_SIZE} -ea $_MYAPP_MAIN_CLASS
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:

Code:
    14-Feb-2011 19:46:28 com.wcg.game.DefaultUncaughtExceptionHandler uncaughtException
    SEVERE: Main game loop broken by uncaught exception
    java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
       at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
       at java.lang.Runtime.loadLibrary0(Runtime.java:823)
       at java.lang.System.loadLibrary(System.java:1028)
       at org.lwjgl.Sys$1.run(Sys.java:73)
       at java.security.AccessController.doPrivileged(Native Method)
       at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
       at org.lwjgl.Sys.loadLibrary(Sys.java:82)
       at org.lwjgl.Sys.<clinit>(Sys.java:99)
       at org.lwjgl.opengl.Display.<clinit>(Display.java:130)
       at com.jme.system.lwjgl.LWJGLDisplaySystem.setTitle(LWJGLDisplaySystem.java:118)
       at com.wcg.game.WcgStandardGame.initSystem(WcgStandardGame.java:287)
       at com.wcg.game.WcgStandardGame.run(WcgStandardGame.java:185)
       at java.lang.Thread.run(Thread.java:662)
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 on the bash terminal that is working. Any ideas, solutions, most welcome. Is there a special way to load libraries when using a shell for Java?

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.

I have also tried the absolute file path: -Djava.library.path="/home/riz/MyGame/lwjgl/native/linux" and this does not work either, same error trace.

There must be something obvious I am missing. I call the shell script from bash like this:

Code:
sh MyGame.sh
No need for root privilege.

Any tips, ideas most welcome.

Thanks
Riz
 
Old 02-16-2011, 08:12 AM   #2
pgroover
Member
 
Registered: Sep 2005
Location: Colorado
Distribution: Ubuntu
Posts: 55

Rep: Reputation: 16
Have you tried changing to the directory it's located at when the script starts? It's been awhile since I've worked in Linux, but I believe a shell started from a script starts off in the user's home directory. That may be the problem, sorry if I'm wrong but like I said, it's been awhile and sometimes it seems like I'm starting all over.
 
Old 02-16-2011, 08:30 AM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2014.08, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 13,926

Rep: Reputation: 2587Reputation: 2587Reputation: 2587Reputation: 2587Reputation: 2587Reputation: 2587Reputation: 2587Reputation: 2587Reputation: 2587Reputation: 2587Reputation: 2587
I'd guess, the shell script should start with :

Line 1 : #!/bin/bash
Line 2 : cd /home/riz/MyGame
 
Old 02-16-2011, 01:36 PM   #4
rizwanjavaid
LQ Newbie
 
Registered: Feb 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for all your suggestions. I have solved the problem. The line:

Code:
_VM_PROPERTIES='-Djava.library.path="lwjgl/native/linux"'
should be:

Code:
_VM_PROPERTIES=-Djava.library.path="lwjgl/native/linux"
(no single quotes) as later on when I invoke the command, it does not deal with the quotes in the same way and fails even though echoing the command looks right.

Thanks again
Riz
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to make a bash script keep running in same terminal after it calls second script? JohnRock Linux - Newbie 4 06-25-2010 09:16 AM
invoking windows command inside a shell script nano2 Programming 6 09-09-2009 03:46 AM
Invoking a shell script remotely. niks27 Linux - Newbie 1 10-11-2007 07:22 AM
bash script--variables have unexpected values on invoking mplayer stairwayoflight Programming 5 07-08-2007 11:17 AM
gnome-terminal fails to give bash prompt wfhoney Red Hat 8 04-21-2004 03:38 PM


All times are GMT -5. The time now is 01:50 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration