Re: Java server won't run after reboot

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 






Ok, the trick is to call Your server class as 'java Server' with the
classpath set to whereever your classes are and not

"java /usr/local/classes/Server"

The package statement gives you a namespace to allow similarly named
classes in various places. Otherwise classes had to have unique names
universally. The namespaces get  mapped to filesystem paths which is one
possible solution. To get around the awkwardness of handling filesystem
subtrees people build  .jar files which can be passed around and also put
into a classpath statement.
When you start a class you always start a class fully qualified i.e.
package name and class name for example

java toms.example.TestClass

The classpath usually contains the local dir as part of the path that's why
classes are found when you are in the dir. Otherwise use the classpath to
point to the dir which contains the package (if there is one) or the
classes.

Example:
Class is called Test and starts with

package toms.example;

...

It resides in ~/projects/classes/toms/example/Test

To start it you have to tell the interpreter where the classes are and what
to start:

java -cp ~/projects/classes toms.example.Test

You can also zip the package by zipping the filesystem from toms on so the
path inside starts with tom. You then call it by issuing

java -cp ~/projects/classes/Test.zip toms.example.Test


For compiling same story, tell the compiler where it should look for
sources exclusing the package part of the paths again and tell it where to
put the results again exclusing the package parts.

For more questions shout at me .-)

Thomas


----- Message from "Reuben D. Budiardja" <techlist@xxxxxxxxxxxxxxxxxxxx> on
Mon, 31 May 2004 08:35:49 -0400 -----
                                                                           
      To: Michael Sullivan <msulli1355@xxxxxxxxxxxxxxxx>,                  
          redhat-list@xxxxxxxxxx                                           
                                                                           
 Subject: Re: Java server won't run after reboot                           
                                                                           

On Saturday 29 May 2004 05:44 pm, you wrote:
> That didn't work.  I still get the NoClassDefFoundError.  Any other
> ideas?

You're right !! it doesn't work. I just try this myself, and whenever I try
to
execute from outside the directory where the java files is located, I got
the
same error. I thought I've seen this and what I suggested was the solution,

obviously not ! (Now it should be obvious that I am not a java developer
myself, I just play with it sometime)

After some searching myself, I only have this solution:

If for example, my java program is in ~/project/testjava/helloworld.java, I

can put in helloworld.java:

package project.testjava;
<rest of the src code>

then I need to go to ~, and compile it from there:
javac project/testjava/helloworld.java

and running it from there would work tpp:
java project/testjava/helloworld

The problems with the solution: First, I can't find a way so that I can use

absolute path during compile and running (which is probably what you want
in
your case, since you're going to put the command in rc.local). So what I
want
is something so that I can say:

javac /home/<username>/project/testjava/helloworld.java
java /home/<username>/project/testjava/helloworld

when I tried, the solution does not work. I can't also figure out what to
put
in after the "package" keyword in the source code to make the absolute path

work.

Secondly, the source code is dependent on what directory you want to
compile
and run the java program from. Unless I am missing something, that is just
plain stupid !! Source code of a program should never be dependent on where

the program is running from.

So that's it. I am kinda stuck right now too. I don't know if that would
help
you, but if you find the real solution, please let me know, cause right now

it bugs the hell out of me too ! (BTW, I have a task of writing some java
program in the near future, so this would be good to know).

I know this is going OT, but if anyone else on the list know a solution,
please help.

RDB


> On Sat, 2004-05-29 at 11:59, Reuben D. Budiardja wrote:
> > On Saturday 29 May 2004 12:16 pm, Michael Sullivan wrote:
<snip>I wrote a java server that I want to start every time
> > > my server PC restarts.  I created a /usr/local/classes directory and
> > > copied Server.class and the support classes it uses there.  Id cd'd
to
> > > /usr/local/classes and issued a java Server from there and it works
> > > fine, but if I issue a java /usr/local/classes/Server from anywhere
> > > outside the /usr/local/classes directory it tells me
> > >
> > > Exception in thread "main" java.lang.NoClassDefFoundError:
> > > /usr/local/classes/Server
<snip>
> > Try the following:
> > set the environment variable CLASSPATH to /usr/local/classes so that
Java
> > knows where to find your classes. Asumming you're using bash:
> > $> export CLASSPATH=$CLASSPATH:/usr/local/classes
> >


--
Reuben D. Budiardja
Department of Physics and Astronomy
The University of Tennessee, Knoxville, TN
---------------------------------------------------------
"To be a nemesis, you have to actively try to destroy
something, don't you? Really, I'm not out to destroy
Microsoft. That will just be a completely unintentional
side effect."
                 - Linus Torvalds -




------------
WebSphere Solutions Workflow Development
Software Solutions Development Lab
IBM Deutschland Entwicklung GmbH
email: muehle@xxxxxxxxxx
Tel: +49-7031-16-4348, Fax: -4890

An onomatopoeia is a word that imitates the sound it represents
(greek for name-making)


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux