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

Discussion in 'Javascript' started by gh@nsbasic.com, Sep 29, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. Guest

    On Sep 29, 9:54 pm, "" <> 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?
    , Sep 29, 2007
    #2
    1. Advertising

  3. 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>
    Thomas 'PointedEars' Lahn, Sep 29, 2007
    #3
  4. Guest

    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, 2007
    #4
  5. 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>
    Thomas 'PointedEars' Lahn, Sep 30, 2007
    #5
  6. Guest

    >
    > 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, 2007
    #6
  7. 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$>
    Thomas 'PointedEars' Lahn, Sep 30, 2007
    #7
  8. Guest

    On Sep 29, 3:54 pm, "" <> 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.)
    , Oct 1, 2007
    #8
  9. On Oct 1, 12:27 pm, "" <> wrote:
    > On Sep 29, 3:54 pm, "" <> 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
    Peter Michaux, Oct 1, 2007
    #9
  10. Guest

    On Oct 1, 4:42 pm, Peter Michaux <> 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! :)
    , Oct 1, 2007
    #10
  11. 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
    Thomas 'PointedEars' Lahn, Oct 1, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tack
    Replies:
    11
    Views:
    2,061
    Andrew Thompson
    Jun 29, 2008
  2. kpowell10
    Replies:
    4
    Views:
    182
    Ben Morrow
    May 7, 2004
  3. PerlFAQ Server
    Replies:
    0
    Views:
    386
    PerlFAQ Server
    Mar 15, 2011
  4. manos

    jslint via command line (rhino?)?

    manos, Jul 14, 2005, in forum: Javascript
    Replies:
    1
    Views:
    97
    manos
    Jul 15, 2005
  5. Garrett Smith

    Non-Browser javascript Implementations - Rhino

    Garrett Smith, Apr 12, 2010, in forum: Javascript
    Replies:
    37
    Views:
    541
    Garrett Smith
    May 2, 2010
Loading...

Share This Page