a href="xn--fiqr16adi7bgnc.xn--dqr445bdw4a.xn--j6w193g">隆鎮,Hacker News,Network Security,Hacker News,1N4148
Compile Javascript File (Windows XP) - Java Rhino,JavaScript Rhino Tutorial
Tutorials‎ > ‎

Compile Javascript File (Windows XP)

Background

To compile a JavaScript file into java byte code invoke the following class

org.mozilla.javascript.tools.jsc.Main 

In most of the time, if we want to compile the JavaScript file, we should start a Rhino session in order to invoke the org.mozilla.javascript.tools.jsc.Main class.  This may be trivial if we have to compile a batch of files at a time.  Thus, it's better if we can have a command instead of invoking a jar class file. 


Preparation of jsc command

The followings steps are used for creating jsc command for future use:
  1. Enter the Java code for the Jsc class as followings:
  2. Save the Java file into c:\rhino\Jsc.java
  3. compile the Jsc.java into Jsc.class
  4. Enter the jsc.bat as followings:
  5. Save the jsc.bat to c:\rhino\jsc.bat

  6. Using the Administrator privilege to "right-click" the "My Computer" and select the "Properties" option

  7. Choose the "Advanced" tab and click the "Environment Variables" button
  8. Select the path variable (under System Variables is preferred), 
  9. add ";c:\rhino" as the end
  10. Choose the "CLASSPATH" variable, and add ";c:\rhino" at the end
  11. Now, you can return to a normal user privilege
Compile a sample HelloWorld.js file
  1. Enter a HelloWorld.js file with the following 
  2. Save the file to c:\js\HelloWorld.js
  3. invoke the "jsc HelloWorld.js" command and you may type "dir" to see the compiled HelloWorld.class file

  4. execute the HelloWorld.class by "java HelloWorld"