Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Rhino: Script runs from command line, but not from browser

Reply
Thread Tools

Rhino: Script runs from command line, but not from browser

 
 
gh@nsbasic.com
Guest
Posts: n/a
 
      09-29-2007
I have a short JS program that runs fine from the command line:

#!/usr/bin/java org.mozilla.javascript.tools.shell.Main
print("Hello World");

I saved it as HelloWorld.js. (It's the shabang that makes it a
JavaScript program, not the .js.)

However, if I start it from Safari or Firefox, I get the following
message in the log:
Exception in thread "main" java.lang.NoClassDefFoundError: org/mozilla/
javascript/tools/shell/Main

Any ideas?

(The webserver is Apache on a Mac)

 
Reply With Quote
 
 
 
 
timsamshuijzen@gmail.com
Guest
Posts: n/a
 
      09-29-2007
On Sep 29, 9:54 pm, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> Any ideas?


Remove the first line from the HelloWorld.js, then it should run in
your browser.
If you want to execute the script from the command line:

/usr/bin/java org.mozilla.javascript.tools.shell.Main HelloWorld.js

Or am I misunderstanding the problem?

 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      09-29-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I have a short JS program that runs fine from the command line:
>
> #!/usr/bin/java org.mozilla.javascript.tools.shell.Main
> print("Hello World");
>
> I saved it as HelloWorld.js. (It's the shabang that makes it a
> JavaScript program, not the .js.)


It is the _shebang_ that makes it a Java program that accepts JavaScript
code as input (by running the JavaScript shell). That is different from
being a (server-side) JavaScript script.

> However, if I start it from Safari or Firefox, I get the following
> message in the log:
> Exception in thread "main" java.lang.NoClassDefFoundError: org/mozilla/
> javascript/tools/shell/Main


This a Java problem, and so off-topic here. Check your CLASSPATH variable
or use the -classpath argument for the `java' command.

http://www.mozilla.org/rhino/


PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
 
Reply With Quote
 
timsamshuijzen@gmail.com
Guest
Posts: n/a
 
      09-30-2007
How about this one:

#!/usr/bin/java org.mozilla.javascript.tools.shell.Main
alert("Hello World! ... oh, damn, I've popped up on the server side :-
( . Can someone come over to the datacenter and click me away, please?
Help!");

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      09-30-2007
(E-Mail Removed) wrote:
> How about this one:
>
> #!/usr/bin/java org.mozilla.javascript.tools.shell.Main
> alert("Hello World! ... oh, damn, I've popped up on the server side :-
> ( . Can someone come over to the datacenter and click me away, please?
> Help!");


Please get a minimum clue and refrain from further such nonsense postings.
Thanks in advance.


PointedEars, Score adjusted
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
 
Reply With Quote
 
gh@nsbasic.com
Guest
Posts: n/a
 
      09-30-2007
>
> Remove the first line from the HelloWorld.js, then it should run in
> your browser.
> If you want to execute the script from the command line:
>
> /usr/bin/java org.mozilla.javascript.tools.shell.Main HelloWorld.js
>
> Or am I misunderstanding the problem?


Where I'm going with this is that I want to invoke JS as a result of a
CGI call. I used the browser as an example: it's an easy way to
reproduce the problem. The same error happens when the script is
called via Apache.

It's not unreasonable to post the question here. The people in this
group are most likely to have experience with this situation. Rhino
JavaScript being written in Java does not make it a Java only
question.

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      09-30-2007
(E-Mail Removed) wrote:
> It's not unreasonable to post the question here. The people in this
> group are most likely to have experience with this situation. Rhino
> JavaScript being written in Java does not make it a Java only
> question.


Nobody said that it was. However, you get a *Java* error when invoking the
JavaScript shell *Java* class (as you could with any Java class), and so you
should ask in a *Java* group if my classpath suggestion did not help.

JavaScript *programming* issues with Rhino are a completely different
matter, they are on-topic here.

Please provide proper attribution next time. http://jibbering.com/faq/


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$(E-Mail Removed)>
 
Reply With Quote
 
gh@nsbasic.com
Guest
Posts: n/a
 
      10-01-2007
On Sep 29, 3:54 pm, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> I have a short JS program that runs fine from the command line:
>
> #!/usr/bin/java org.mozilla.javascript.tools.shell.Main
> print("Hello World");
>
> I saved it as HelloWorld.js. (It's the shabang that makes it a
> JavaScript program, not the .js.)
>
> However, if I start it from Safari or Firefox, I get the following
> message in the log:
> Exception in thread "main" java.lang.NoClassDefFoundError: org/mozilla/
> javascript/tools/shell/Main
>
> Any ideas?
>
> (The webserver is Apache on a Mac)


I've solved the problem. It's Apache, not being able to find js.jar.
My guess is that Apache keeps the cgi scripts restricted to the
directories it knows about. If I use the default classpath, as above,
or explicitly specify it (~/Library/Java/Extensions), Apache won't let
it open, resulting in the class not being found.

If I move the js.jar file to my cgi-bin folder, the following script
works just fine:
#!/usr/bin/java -classpath js.jar
org.mozilla.javascript.tools.shell.Main
print("Content-type: text/plain");
print("");
print("Hello World");

(Note that I also had to add a Content-Type and a blank line.)

 
Reply With Quote
 
Peter Michaux
Guest
Posts: n/a
 
      10-01-2007
On Oct 1, 12:27 pm, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> On Sep 29, 3:54 pm, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>
>
>
> > I have a short JS program that runs fine from the command line:

>
> > #!/usr/bin/java org.mozilla.javascript.tools.shell.Main
> > print("Hello World");

>
> > I saved it as HelloWorld.js. (It's the shabang that makes it a
> > JavaScript program, not the .js.)

>
> > However, if I start it from Safari or Firefox, I get the following
> > message in the log:
> > Exception in thread "main" java.lang.NoClassDefFoundError: org/mozilla/
> > javascript/tools/shell/Main

>
> > Any ideas?

>
> > (The webserver is Apache on a Mac)

>
> I've solved the problem. It's Apache, not being able to find js.jar.
> My guess is that Apache keeps the cgi scripts restricted to the
> directories it knows about. If I use the default classpath, as above,
> or explicitly specify it (~/Library/Java/Extensions), Apache won't let
> it open, resulting in the class not being found.
>
> If I move the js.jar file to my cgi-bin folder, the following script
> works just fine:
> #!/usr/bin/java -classpath js.jar
> org.mozilla.javascript.tools.shell.Main
> print("Content-type: text/plain");
> print("");
> print("Hello World");
>
> (Note that I also had to add a Content-Type and a blank line.)


I don't think you want to run a Java-based CGI script for production.
Firing up the JVM for each request is much overhead.

Peter

 
Reply With Quote
 
gh@nsbasic.com
Guest
Posts: n/a
 
      10-01-2007
On Oct 1, 4:42 pm, Peter Michaux <(E-Mail Removed)> wrote:

> I don't think you want to run a Java-based CGI script for production.
> Firing up the JVM for each request is much overhead.
>
> Peter


I agree - certainly not!

I was looking for a way to do local testing of both the server and
client side on a Mac. Now I can get to work!

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 9.2 My CGI script runs from the command line but not the browser. (500 Server Error) PerlFAQ Server Perl Misc 0 03-15-2011 04:00 PM
Runs in Eclipse but not from command line Tack Java 11 06-29-2008 05:03 PM
Script runs in IDLE but not by itself!? Scott Python 1 07-18-2004 10:22 PM
Perl script runs from command prompt but not from Task Scheduler in Win2000 kpowell10 Perl Misc 4 05-07-2004 10:44 PM
Python Program runs but itself but does not run under IDLE Ollie Python 0 10-02-2003 04:05 PM



Advertisments