LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-01-2010, 04:16 AM   #1
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Rep: Reputation: 0
Problem running .sh script with "screen" and "java"


Hello.
I have a VPS.
I am trying to run a java application with "screen" (so I can close PuTTy and it will still run)

This is my run.sh
Code:
screen 
cd bin
echo Press Crtl + A + D to detach!
java -Xmx300m -cp .:./bin.:./deps/poi.jar:deps/mysql.jar:deps/mina.jar:deps/slf4j.jar:deps/slf4j-nop.jar:deps/jython.jar:log4j-1.2.15.jar server.Server -server
When I run this run.sh script, this is the output.

Code:
[server@agentblue ~]$ ./run.sh
[screen is terminating]
: No such file or directory
Press Crtl + A + D to detach!
Exception in thread "main" java.lang.NoClassDefFoundError: server/Server
Caused by: java.lang.ClassNotFoundException: server.Server
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
But if I then type in the commands myself
Here are the commands I type in
Code:
cd bin
java -Xmx300m -cp .:./bin.:./deps/poi.jar:deps/mysql.jar:deps/mina.jar:deps/slf4j.jar:deps/slf4j-nop.jar:deps/jython.jar:log4j-1.2.15.jar server.Server -server
The java application/server runs.

What is wrong with my run.sh script?

I have chmod'ed it to 777.
Thanks.
 
Old 06-01-2010, 04:36 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
So just to confirm, when you run the script manually you are still in your home directory?

The error on line 2 indicates that there is no bin directory in your home directory.
 
Old 06-01-2010, 04:39 AM   #3
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
When I use the script, I am running it from /home/server/ where run.sh is located.
(server is my login for that account)
When I am typing the commands I am in /home/server/ then when I type cd bin it changes to /home/server/bin
 
Old 06-01-2010, 04:43 AM   #4
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Your problem here is the "cd bin" line.

In your script change it to "cd /home/server/bin" and retry - this should solve the problem.

Last edited by alli_yas; 06-01-2010 at 04:45 AM.
 
Old 06-01-2010, 04:46 AM   #5
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alli_yas View Post
Your problem here is the "cd bin" line.

I suspect when you manually run the command; you are first in your java install directory and then change directory to /my/java/installation/bin - where the java executable is located.

Best way to solve your problem is to add the following to your .bash_profile:

Code:
JAVA_HOME=/my/location/to/java/jdk1.6.0_20
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
What this will do is setup your Java binary directory to be in your PATH environment variable.

Thereafter you can remove line 2 from your script altogether and running it thereafter (whether in a screen or not) will work
Not really.
The reason why I do 'cd bin' is because in the 'bin' is where my java .class files are.
JDK is install to /home/server/jdk1.6.0_20

Edit:

Last edited by IJustinI; 06-01-2010 at 04:50 AM.
 
Old 06-01-2010, 04:48 AM   #6
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Apologies - I only saw your post #3 after my previous post - which I've edited accordingly....try what I've suggested after editing.
 
Old 06-01-2010, 04:50 AM   #7
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
I changed the 'cd bin' to 'cd /home/server/bin' and i now get this
Code:
[server@agentblue ~]$ ./run.sh
[screen is terminating]
: No such file or directory/server/bin
Press Crtl + A + D to detach!
Exception in thread "main" java.lang.NoClassDefFoundError: server/Server
Caused by: java.lang.ClassNotFoundException: server.Server
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
[server@agentblue ~]$
 
Old 06-01-2010, 04:56 AM   #8
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Post the output of:

Code:
#ls -la /home/server
What is the purpose of the bin directory - solely to store your class files?

I notice your java call is quite a complex one - what exactly does that do?
 
Old 06-01-2010, 04:59 AM   #9
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alli_yas View Post
Post the output of:

Code:
#ls -la /home/server
What is the purpose of the bin directory - solely to store your class files?

I notice your java call is quite a complex one - what exactly does that do?
Code:
[server@agentblue ~]$ ls -la /home/server
total 68
drwx------  7 server server 4096 Jun  1 13:01 .
drwxr-xr-x  3 root   root   4096 May 31 14:07 ..
-rw-------  1 server server 8328 Jun  1 13:36 .bash_history
-rw-r--r--  1 server server   33 May 31 14:07 .bash_logout
-rw-r--r--  1 server server  176 May 31 14:07 .bash_profile
-rw-r--r--  1 server server  124 May 31 14:07 .bashrc
drwxr-xr-x  5 server server 4096 Jun  1 11:53 bin
-rw-r--r--  1 server server  710 Jun  1 10:50 .classpath
drwxr-xr-x  8 server server 4096 Jun  1 12:01 Data
drwxr-xr-x  2 server server 4096 May 31 14:19 deps
drwxr-xr-x 10 root   root   4096 May 31 14:41 jdk1.6.0_20
-rw-r--r--  1 server server  383 Jun  1 10:50 .project
-rwxrwxrwx  1 server server    9 Jun  1 12:56 resume
-rwxrwxrwx  1 server server  192 Jun  1 13:53 run.sh
drwxr-xr-x  3 server server 4096 May 31 14:19 src
[server@agentblue ~]$
The java line loads a RuneScape private server as it is using .jars as deps (like framework, eg; mysql, apatch) The class file that it is should be loading is located in;
/home/server/bin/server/Server.class
 
Old 06-01-2010, 05:03 AM   #10
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Hmmm...then what's in /home/server/bin; if your actual class files are in /home/server/bin/server?
 
Old 06-01-2010, 05:04 AM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well this would seem to say that somewhere you are not giving us the whole picture??
Why are we getting:
Quote:
: No such file or directory/server/bin
if you have put in:
Quote:
cd /home/server/bin
the /home part seems to be missing and the directory still does not exist
 
Old 06-01-2010, 05:04 AM   #12
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alli_yas View Post
Hmmm...then what's in /home/server/bin; if your actual class files are in /home/server/bin/server?
[server@agentblue bin]$ ls
deps scripts server
[server@agentblue bin]$
 
Old 06-01-2010, 05:11 AM   #13
IJustinI
LQ Newbie
 
Registered: Jun 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grail View Post
Well this would seem to say that somewhere you are not giving us the whole picture??
Why are we getting:

if you have put in:

the /home part seems to be missing and the directory still does not exist
I don't know what piece of information I am not giving you.
If you have teamviewer you can view my computer and look around
 
Old 06-01-2010, 05:12 AM   #14
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
What happens if you take out the reference to screen in the script?
 
Old 06-01-2010, 05:12 AM   #15
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Can you not tarball it and host it somewhere so we can try it?

EDIT: After testing a simpler version your script wont work anyway, it'll start screen, then when screen terminates it'll run the java. Its procedural, you want
Code:
screen cmd

Last edited by jamescondron; 06-01-2010 at 05:16 AM.
 
  


Reply



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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 03:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:06 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