[SOLVED] Problem running .sh script with "screen" and "java"
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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
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:
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 ~]$
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.