Meaningless Drivel is fun!*
The moose likes General Computing and the fly likes included class works from command line, can't be found when run by BigBrother program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "included class works from command line, can Watch "included class works from command line, can New topic
Author

included class works from command line, can't be found when run by BigBrother program

Jon Walser
Greenhorn

Joined: Jul 23, 2012
Posts: 6
BigBrother is a monitoring system that can run user-developed code. It runs a standard UNIX shell script that can call other programs...this time, a groovy script.

The script (pass_status.groovy) can be run from the command line >groovy pass_status.groovy and it runs as designed.
When executed by the BigBrother script, it cannot resolve a class.

import password.PasswordUtil

I have captured the CLASSPATH environment variable that is in place when I execute from the command line, and captured, into a file the environment when pass_status.groovy attempts to run.
They are identical This makes sense as the environment is set by running the same file in either case.

I am running under the same account that BigBrother runs under.
GROOVY_HOME, PATH, JAVA_HOME are also identical, and set by the same file.

Thanks for any ideas...
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

I am not sure if this an issue with Groovy. You must check with BigBrother documentation to see how such operations can be performed.

Moving it to corresponding forum for now. If you are able to find out if this is not an issue with BigBrother tool then we can move it back to Groovy forum.


Mohamed Sanaulla | My Blog
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37970
    
  22
Welcome to the Ranch

Is that import statement in Java? Which folder/jar/whatever is the PasswordUtil .class file in? I suggest you confirm what the classpath is by echoing it to the command line.
Jon Walser
Greenhorn

Joined: Jul 23, 2012
Posts: 6
1. Groovy vs BigBrother:
Clearly the issue is a mix of the two. Something is different when BigBrother triggers a shell script that calls a groovy script that includes a java class and it fails, but the same shell->groovy>java works from the command line. The question is what could cause Groovy to be unable to pick up the java class when the CLASSPATH is demonstrably identical. My understanding of the underlying assumptions of Groovy is totally inadequate to solve this question.
2. The import is of a compiled java class. It resides in $GROOVY_HOME/lib/password/PasswordUtil.class. The CLASSPATH includes $GROOVY_HOME/lib/password. I have tried including $GROOVYHOME/lib/password/PasswordUtil.class, as if it were a jar file, to no effect.

Perhaps I need to jar the class?

Thanks to both of you for looking
Jon Walser
Greenhorn

Joined: Jul 23, 2012
Posts: 6
Some additional progess, of a sort:

I was able get my command line execution to quit working. Additionally, I find the problem is not limited to password.PasswordUtil:

$GROOVY_HOME/lib/password/PasswordUtil.java -> package password
.java file compiled to PasswordUtil.class and thence to PasswordUtil.jar

At this point, command line works.

Renamed PasswordUtil.class and ensured CLASSPATH had $GROOVY_HOME/lib/password/PasswordUtil.jar

Command line now fails like the BB triggered version. Import is NOT finding .jar file from CLASSPATH.

As a test: added import BlowfishJ.BlowfishECB to groovy file and it also fails. However, before I broke the command-line version, it was being found by PasswordUtil (java file).

Guessing: import in a groovy file is not the same as import in a java file. And/or, my package, directory and CLASSPATH designations are faulty.

I'm also wondering if I must compile the Groovy script to pick up the imports...
Jon Walser
Greenhorn

Joined: Jul 23, 2012
Posts: 6
Looks like we got this thing to work, and in case anyone is following, here is what we did:
Problem 1: Why running from command line worked and from BigBrother did not:
-from the command line, groovy was finding the .class file. When that was removed (leaving the .jar) the command line quit too.

Problem2: groovy pass_status.groovy was not looking in the environmental variable CLASSPATH.
-In order to get the program to use CLASSPATH, groovy had to be executed with the –cp $CLASSPATH option.

Problem3: Even at this point, I still wasn’t finding the PasswordUtil class.
-When I created the PasswordUtil.jar file, I was in the $GROOVY_HOME/lib/password directory. Taking a look at the .jar file, PasswordUtil was defined, but not password/PasswordUtil. (Package password.) When the .jar file was re-created from the lib directory, it made a useable .jar file and all is right with the world!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37970
    
  22
Well done getting it sorted
 
 
subject: included class works from command line, can't be found when run by BigBrother program
 
Similar Threads
difference between ./sh and . ./sample.sh
How do I install a 3rd party module in Groovy?
Crontab & Procmail problem
java command - where should it be called
String class can't find split method: wrong java version?