Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:34:17+00:00 2026-05-31T02:34:17+00:00

Alright, so I created a JavaScript file named HelloWorld.js with the following contents: java.lang.System.out.println(Hello

  • 0

Alright, so I created a JavaScript file named HelloWorld.js with the following contents:

java.lang.System.out.println("Hello World!");

Now, I compiled it using the Rhino JavaScript Compiler using the following command (the js.jar file is in my classpath):

java org.mozilla.javascript.tools.jsc.Main HelloWorld.js

It compiled the JavaScript file and created the Java class file as expected. Then I tried to execute the Java class file by calling java HelloWorld. However, it generated the following error message:

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: HelloWorld. Program will exit.

I tried to understand what caused the java.lang.NoClassDefFoundError to be thrown, and from what I read in this blog post I learned that the java.lang.NoClassDefFoundError is thrown if a class was present during compile time but not available in Java classpath during runtime.

So I ran the javap HelloWorld command to check what the problem is, and this is what I got:

public class HelloWorld extends org.mozilla.javascript.NativeFunction implements org.mozilla.javascript.Script {
    public HelloWorld();
    public static void main(java.lang.String[]);
    public final java.lang.Object exec(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable);
    public final java.lang.Object call(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, org.mozilla.javascript.Scriptable, java.lang.Object[]);
    public int getLanguageVersion();
    public java.lang.String getFunctionName();
    public int getParamCount();
    public int getParamAndVarCount();
    public java.lang.String getParamOrVarName(int);
    public boolean getParamOrVarConst(int);
}

Now, what I understand from this is that the HelloWorld class is present and is declared as public. Hence there shouldn’t be any reason why the Java Virtual Machine can’t find it. This is where I’m confused. I don’t know where to go from here, nor what to do to resolve this problem.

I found out that I could execute the Java class file if I invoked Rhino to call the exec method on an instance of HelloWorld as follows:

java -jar /usr/share/rhino/js.jar HelloWorld.class

However, I would like to execute the Java class file using the java HelloWorld command directly since the js.jar file already in my classpath. I would like to understand what the problem is so that I know what’s really happening behind the scenes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:34:19+00:00Added an answer on May 31, 2026 at 2:34 am

    Are you sure the class file is on the classpath (as well as js.jar)?

    Try

    java -cp .;js.jar HelloWorld
    

    (assuming HelloWorld.class in the current directory, otherwise something like -cp build;js.jar).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, currently I have my SWF hitting a php file that will go and
Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Alright, I'm trying to read a comma delimited file and then put that into
Alright, I know how the fieldset / legend works out in HTML. Say you
Alright so far I have created a list containing a long list of words
Alright so far I have created a list containing a long list of words
Alright so I've already created a PHP bug about this but it was marked
Alright. This is the situation. I have created a website with a black banner
Alright, need some help created a query for an Oracle 10g DB. I have
Alright, so I'm using arc4random to get a random image out of an array,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.