473,414 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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

gh
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)

Sep 29 '07 #1
10 8295
On Sep 29, 9:54 pm, "g...@nsbasic.com" <g...@nsbasic.comwrote:
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?

Sep 29 '07 #2
gh@nsbasic.com 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>
Sep 29 '07 #3
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!");

Sep 30 '07 #4
ti************@gmail.com 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>
Sep 30 '07 #5
gh
>
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.

Sep 30 '07 #6
gh@nsbasic.com 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, <f8*******************@news.demon.co.uk>
Sep 30 '07 #7
gh
On Sep 29, 3:54 pm, "g...@nsbasic.com" <g...@nsbasic.comwrote:
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.)

Oct 1 '07 #8
On Oct 1, 12:27 pm, "g...@nsbasic.com" <g...@nsbasic.comwrote:
On Sep 29, 3:54 pm, "g...@nsbasic.com" <g...@nsbasic.comwrote:
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

Oct 1 '07 #9
gh
On Oct 1, 4:42 pm, Peter Michaux <petermich...@gmail.comwrote:
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! :-)

Oct 1 '07 #10
gh@nsbasic.com wrote:
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! :-)
You're welcome.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Oct 1 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: CoralineSage | last post by:
Hi there, I know very little about PHP, but I was just curious to know why exactly would some PHP code run fine from the command line but not from the browser? I'm just curious. I was working...
3
by: #pragma once | last post by:
That's all we are expecting from programs written in the managed code; Though a MVP advised not to say that, because after JIT compilation the code runs in the native! Funny, isn't? That means...
1
by: manos | last post by:
Hi all, I was wondering if anyone has managed to "validate" js file using jslint from the command line with an engine like rhino. Any suggestions/experiences really appreciated. Many thanks,...
8
by: pas805 | last post by:
I have a PHP page that I would like to run with cron but that's not the problem. My problem come when I run my script throw my browser the script runs properly but when I try to run the script...
11
by: Dave Schwimmer | last post by:
I am relatively new to PHP. One of the things that seems glaring obvious to me (coming from a C/C++ background) is how 'open' everything seems - (AFAIK). For instance, URLs typically have the name...
3
by: uzzi | last post by:
I don't know how to make a php script to work via cron...I want to make it run daily...My server API is CGI/Fast CGI.I have hosting from godaddy and in the help section i found that i have to specify...
1
by: sophie_newbie | last post by:
Hi, I'm running a python script which if I run from the command line as root runs fine. But if I run it through the web-browser as a cgi script gives the following error "Error in X11: unable to...
51
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.