Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-16-2011, 07:25 AM   #1
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:

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):


# Set the minimum and maximum heap sizes

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

if [ "$MYAPP_JAVA_HOME" != "" ] ; then
    if [ -f "$_TMP" ] ; then
        if [ -x "$_TMP" ] ; then
            echo "Warning: $_TMP is not executable"
        echo "Warning: $_TMP does not exist"

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




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 ), I get the UnsatisfiedLinkError message:

    14-Feb-2011 19:46:28 uncaughtException
    SEVERE: Main game loop broken by uncaught exception
    java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
       at java.lang.ClassLoader.loadLibrary(
       at java.lang.Runtime.loadLibrary0(
       at java.lang.System.loadLibrary(
       at org.lwjgl.Sys$
       at Method)
       at org.lwjgl.Sys.doLoadLibrary(
       at org.lwjgl.Sys.loadLibrary(
       at org.lwjgl.Sys.<clinit>(
       at org.lwjgl.opengl.Display.<clinit>(
       at com.jme.system.lwjgl.LWJGLDisplaySystem.setTitle(
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:

No need for root privilege.

Any tips, ideas most welcome.

Old 02-16-2011, 08:12 AM   #2
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
LQ 5k Club
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2016 CentOS6.9 CentOS7.3 + 50+ other Linux OS, for test only.
Posts: 16,696

Rep: Reputation: 3291Reputation: 3291Reputation: 3291Reputation: 3291Reputation: 3291Reputation: 3291Reputation: 3291Reputation: 3291Reputation: 3291Reputation: 3291Reputation: 3291
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
LQ Newbie
Registered: Feb 2011
Posts: 2

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

should be:

(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


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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:25 AM.

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