LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-12-2004, 03:04 AM   #1
rolf_mueller
LQ Newbie
 
Registered: Oct 2004
Location: Bundoora, Australia
Distribution: Fedora Core 2 on Dell PE700
Posts: 12

Rep: Reputation: 0
Starting Java from shell script (Exception in thread "main")


I try to run a Java-Class, which resides in a .jar file, from a shell script.
My script (create-tables.sh) looks like the following:


#!/bin/bash
java -cp :acf.0.9.2.4.jar:acf.scheduler.0.9.2.4.jar:um.0.9.2.4.jar:ims.server.0.9.2.4.jar:mySQLjdbc.jar org.managedimages.ims.server.services.installation.CreateTablesX


When I start the script with ./create-tables.sh, the result will be the following:


[root@rm12 installation]# ./create-tables.sh
Exception in thread "main" java.lang.NoClassDefFoundError: org/managedimages/ims/server/services/installation/CreateTablesX


But when I cut&paste the java command into the console, and run
it directly from the console, the class runs through fine...

JAVA_HOME and PATH are set properly. Is there anything missing
in my shell script? Also, I have the same problem with starting ant,
from the script it doesn't work, from the console it works...

Here is additional info:

[root@rm12 installation]# pwd
/var/managedimages/prod/installation
[root@rm12 installation]# echo $JAVA_HOME
/usr/java/j2sdk1.4.2_05
[root@rm12 installation]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/java/j2sdk1.4.2_05/bin:/usr/local/apache-ant-1.6.2/bin:/root:/root/bin
[root@rm12 installation]# ls -al
total 1908
drwxr-xr-x 2 root root 4096 Oct 12 17:37 .
drwxr-xr-x 6 root root 4096 Oct 12 12:41 ..
-rw-r--r-- 1 root root 493087 Oct 12 12:41 acf.0.9.2.4.jar
-rw-r--r-- 1 root root 40247 Oct 12 12:41 acf.scheduler.0.9.2.4.jar
-rw-r--r-- 1 root root 127 Oct 12 12:41 bootstrap.acf.properties
-rw-r--r-- 1 root root 157 Oct 12 12:41 bootstrap.acf.scheduler.properties
-rw-r--r-- 1 root root 218 Oct 12 12:41 bootstrap.ims.server.properties
-rw-r--r-- 1 root root 252 Oct 12 12:41 bootstrap.properties
-rw-r--r-- 1 root root 150 Oct 12 12:41 bootstrap.um.properties
-rw-r--r-- 1 root root 172 Oct 12 12:41 create-root-user.bat
-rwxr-xr-x 1 root root 196 Oct 12 12:57 create-root-user.sh
-rwxr-xr-x 1 root root 197 Oct 12 12:41 create-root-user.sh~
-rw-r--r-- 1 root root 176 Oct 12 12:41 create-tables.0.9.1.bat
-rwxr-xr-x 1 root root 500 Oct 12 16:54 create-tables-1.sh
-rwxr-xr-x 1 root root 599 Oct 12 16:53 create-tables-1.sh~
-rw-r--r-- 1 root root 170 Oct 12 12:41 create-tables.bat
-rw-r--r-- 1 root root 53438 Oct 12 17:00 create-tables.log
-rwxr-xr-x 1 root root 182 Oct 12 17:37 create-tables.sh
-rwxr-xr-x 1 root root 191 Oct 12 17:12 create-tables.sh~
-rw-r--r-- 1 root root 882037 Oct 12 12:41 ims.server.0.9.2.4.jar
-rw-r--r-- 1 root root 287712 Oct 12 12:41 mySQLjdbc.jar
-rw-r--r-- 1 root root 94602 Oct 12 12:41 um.0.9.2.4.jar
[root@rm12 installation]#
 
Old 10-12-2004, 08:49 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
What happens if you run the script with this:
Code:
bash ./create-tables.sh
This has to be an environment problem. It could be that the environment isn't being inherited by the script; in which case, check that you own the file. From the bash manpage:
Quote:
If the shell is started with the effective user (group) id not equal to the real user (group) id, and the -p option is not supplied, no startup files are read, shell functions are not inherited from the environment, the SHELLOPTS variable, if it appears in the environment, is ignored, and the effective user id is set to the real user id. If the -p option is supplied at invocation, the startup behavior is the same, but the effective user id is not reset.
You could also try adding -p to the shebang line in this case (though I haven't tried this)
(Edit: The shebang line is the one that starts with #!)
 
Old 10-17-2004, 05:50 PM   #3
rolf_mueller
LQ Newbie
 
Registered: Oct 2004
Location: Bundoora, Australia
Distribution: Fedora Core 2 on Dell PE700
Posts: 12

Original Poster
Rep: Reputation: 0
Uff, I found out what the problem was...
I created the shell script in Windows using Eclipse.
This was the version which didn't work. Then,
on my Linux box, I played a bit around with the
kedit editor, as I found by accident, that when I
remove the first CR/LF and re-add it in kedit, the
shell script works!

I can remember exactly, but what was the difference
between Win and iX? iX has <CR> only and Win has <CR><LF>?
Or was it vice versa? Anyway, this is funny behavior...
Does anyone know about this?

Last edited by rolf_mueller; 10-17-2004 at 05:51 PM.
 
Old 10-18-2004, 03:35 AM   #4
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
Windows uses <CR><LF>
UNIX and Linux use <LF> (I think it's LF from cating a file straight to a printer)
I think it's Mac OS that uses <CR> (but it might be the amega or something)

Edit: To a hardware printer, <CR> feed's one line's worth of paper, <LF> moves the head to the beginning of the current line. So you need to send <CR><LF> when printing text.

Last edited by rjlee; 10-18-2004 at 08:10 AM.
 
Old 10-18-2004, 07:41 AM   #5
webtoe
Member
 
Registered: Apr 2001
Location: Cambridge, England
Distribution: Slackware 10, Fedora Core 3, Mac OS X
Posts: 617

Rep: Reputation: 30
Macs do indeed use <CR> (though not sure now that Mac OS X has a BSD core).

I'm going by what I read a while ago but I think it comes from old teletype machiens etc. that were sending messages over telephone wires (similar to FAX machines). The <LF> stands for Line Feed and returns the location of the next character down a line. A separate command would return the cursor to the beginning of the line. <CR> on the other hand does both in one sweep. However, when computers where still maturing different operating systems used either one or the other. MS Windows went for including both just to be sure even though it makes little sense.

Please take this with a pinch of salt since I haven't read up on this for a while. Unfortunately this old over throw of the old days of computers still comes up and bites us in the backside. I usually notice it when move a Linux text file to Windows. Windows will just display it as one solid line of text with a little box to denote where the <LF>'s are.

Alex

P.S. Its been a while since I've posted so go easy on me..... :P
 
Old 10-30-2004, 02:11 AM   #6
rolf_mueller
LQ Newbie
 
Registered: Oct 2004
Location: Bundoora, Australia
Distribution: Fedora Core 2 on Dell PE700
Posts: 12

Original Poster
Rep: Reputation: 0
The lesson I've learned is, that I create the scripts on the Linux system,
test them there, and then copy them over to my development system (win2k)
and check them in...
 
  


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
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window serve paragvd Programming 4 10-05-2004 03:35 AM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 03:47 AM
Exception in thread "main" java.lang.NoClassDefFoundError: Lobais Linux - Software 19 06-23-2004 08:42 AM
Exception in thread "main" java.lang.NoClassDefFoundError: melinda_sayang Programming 2 04-27-2004 11:49 AM
1. shell script "find and replace" on text 2. java GUI application randomx Programming 4 03-05-2004 01:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:49 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration