473,715 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.jav ascript.tools.s hell.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.NoCla ssDefFoundError : org/mozilla/
javascript/tools/shell/Main

Any ideas?

(The webserver is Apache on a Mac)

Sep 29 '07 #1
10 8331
On Sep 29, 9:54 pm, "g...@nsbasic.c om" <g...@nsbasic.c omwrote:
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.jav ascript.tools.s hell.Main HelloWorld.js

Or am I misunderstandin g 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.jav ascript.tools.s hell.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.NoCla ssDefFoundError : 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.jav ascript.tools.s hell.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.jav ascript.tools.s hell.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.jav ascript.tools.s hell.Main HelloWorld.js

Or am I misunderstandin g 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.de mon.co.uk>
Sep 30 '07 #7
gh
On Sep 29, 3:54 pm, "g...@nsbasic.c om" <g...@nsbasic.c omwrote:
I have a short JS program that runs fine from the command line:

#!/usr/bin/java org.mozilla.jav ascript.tools.s hell.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.NoCla ssDefFoundError : 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.jav ascript.tools.s hell.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.c om" <g...@nsbasic.c omwrote:
On Sep 29, 3:54 pm, "g...@nsbasic.c om" <g...@nsbasic.c omwrote:
I have a short JS program that runs fine from the command line:
#!/usr/bin/java org.mozilla.jav ascript.tools.s hell.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.NoCla ssDefFoundError : 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.jav ascript.tools.s hell.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...@g mail.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

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

Similar topics

7
2173
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 with someone else's PHP code that supposedly created MySQL tables in a database and for some reason it just wouldn't create the tables at all (no specific error message). Someone suggested I run from the command line and when I did, it worked...
3
1800
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 scripting languages run in the Host code and never in the native? That means scripting languages are poorer than .NET in speed just because they are hosted by an interpreter? What about .Net run time libraries? Can any one tell me the differences?...
1
1793
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, Manos
8
1587
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 using either php, lynx or wget the script starts but once the request is made the script stops running. EX.: I get a client from my database and send a request to my billing company to get the status of is invoice. So basically the script never...
11
1619
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 of the php script that they are calling - also just viewing the source of most web pages will show you in glorious detail, the paths and names to any PHP scripts they may be using. If one was to implement user authorisation (or any other module...
3
2342
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 the interpreter manually...look what it says: i've tried with /web/cgi-bin/php "$HOME/html/path/to/my/script.php as command and it doesn't work. if i run the script in browser it works...what should i introduce as a command..and do i have...
1
2431
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 start device PNG". Now I should say that this python script is calling fucntions in R (a scripting languange used in statistics) using the python module RPy, so this I dunno if this is entirely a Python question, because as far as I can see the...
51
4141
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 Command Prompt or Browser or some other application? Ojas.
1
47468
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
8821
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8718
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9340
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9196
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9103
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5967
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.