• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to use jsvc but the program continually complains that it can't find my jave class  RSS feed

 
Rob Tanner
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing java app to act as a front end to Postfix and route the message to one if several servers based on the sender and it needs to run as a daemon. I wrote the following shell script to invoke the jsvc wrapper in order to daemonize the app. My problem is that I get the complaint, "java.lang.ClassNotFoundException: org.linfield.eMailRouter.RouterDaemon". I've tried all kinds of different ways to invoke it. I have tried using the class alone and providing a path to the beasty (actually to the containing directory since the actual classfile is three levels down. And in the script below, I've added to a jarfile. I have built the jar file both as an executable jar and as a regular jar. Same error no matter how I do it. The classpaths are correct, so I'm totally baffled. Any idea as to what's wrong?



Thanks,

Rob Tanner
Linfield College
 
Paul Clapham
Sheriff
Posts: 22839
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't really helpful to say that the classpath is correct, not when you have an error message which means it isn't correct. Anyway, am I right in thinking that /home/rtanner/Java/Workspace/eMailRouter/eMailRouter.jar is where that class is supposed to be? It appears that it isn't, at least not in the right place. Have you looked inside that jar file to see if it's built correctly? The root directory inside the jar should be named "org", and so on.
 
Rob Tanner
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though the java code is intended to run as a daemon, I did include a main method for testing that just prints out the message, "I'm in main." So, as far as the path goes, from the command line I can access the class in straight java (not jsvc) with the command:

java -cp /usr/share/java/commons-daemon-1.0.15.jar:/home/rtanner/Java/Workspace/eMailRouter/eMailRouter.jar org.linfield.eMailRouter.RouterDaemon

and I get back the message "I'm in main." Therefore I feel confident in the path. Java can find it but jsvc cannot. So my question is, why not?

~ Rob
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Tanner wrote:CLASS_PATH="/usr/share/java/commons-daemon-1.0.15.jar:/home/rtanner/Java/Workspace/eMailRouter/eMailRouter.jar"

I might be easily wrong here, but I doubt the quotes are needed when setting the variable. I'd even say that they might be the cause of your problem.
 
Tim Holloway
Saloon Keeper
Posts: 18799
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin Vajsar wrote:
Rob Tanner wrote:CLASS_PATH="/usr/share/java/commons-daemon-1.0.15.jar:/home/rtanner/Java/Workspace/eMailRouter/eMailRouter.jar"

I might be easily wrong here, but I doubt the quotes are needed when setting the variable. I'd even say that they might be the cause of your problem.


In this particular case, quotes can be single-quotes, double-quotes, or omitted. Quotes would make a difference if there were spaces in any of the path text, and single-quotes would be required if there were characters that the command shell would otherwise interpret (such as "$").

I don't see anything obviously wrong here, but the java command line does have 2 types of arguments: JVM arguments and application arguments, and I'm virtually certain that JVM arguments must precede the application arguments. So the order in which things are presented may be important.
 
Rob Tanner
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure that the order of arguments has any significance with respect to the JVM because jscv is a daemon written in C and not just an alias to a java executable. It may well be a wild eyed naive presumption but I am assuming that jsvc binary knows which arguments have to be passed to the JVM and which arguments are specific to itself. Nevertheless, since the classpath (-cp) is the only JVM specific argument, I put it at the front of the list and it made no difference. So, just for grins, I copied the jarfile that contained my java app "eMailRouter.jar" up to the jre/lib/ext directory and java had no problem finding the org.linfield.eMailRouter.RouterDaemon class. I don't think that thats an ideal solution, but at least I can develop and test my project while trying to figure out why the JVM couldn't find it before.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!