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

  • Home
  • SEARCH
  • 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 8133117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:30:50+00:00 2026-06-06T09:30:50+00:00

I am using Rhino as part of an Ant build process to bundle and

  • 0

I am using Rhino as part of an Ant build process to bundle and minify JavaScript. In addition to that, I would also like pre-compile client-side templates, i.e. compile them from markup to JavaScript. At a glance, I thought Rhino’s serialize() method would do it but that does not seem to be the case.

// Load templating engine
load( "engine.js" );

// Read template file
var template = readFile( "foo.template" ),

// Compile template
compiled = engine.compile( template );

// Write compiled template to file
serialize( compiled, "compiledFoo.js" );

This results in a binary file being written. What I want is a text file which contains the compiled template.

If using serialize() is not the answer, then what is? Since it’s Rhino, it would be possible to import Java classes as well. Offhand, I can’t figure out a way to do it.

I know this can be done in Node but I’m not in a position to migrate the build process from Ant-Rhino to Grunt-Node right now.

  • 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-06-06T09:30:51+00:00Added an answer on June 6, 2026 at 9:30 am

    In my search for an answer I came across the fact that SpiderMonkey, Rhino’s C/C++ sister, has an uneval() function, which as you can guess does the opposite of JavaScript’s eval() function. One more Google search later, I found that Rhino implemented uneval() in 1.5R5. This may be the only documentation that mentions Rhino has this feature (or not).

    That being said, here is the solution:

    // Load the templating engine
    load( "engine.js" );
    
    // Read the template file
    var template = readFile( "foo.template" ),
    
    // Compile the template markup to JavaScript
    compiled = engine.compile( template ),
    
    // Un-evaluate the compiled template to text
    code = uneval( compiled ),
    
    // Create the file for the code
    out = new java.io.FileWriter( "foo.js" );
    
    // Write the code to the file
    out.write( code, 0, code.length );
    out.flush();
    out.close();
    
    quit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there any example on using java method to call rhino-javascript function and return
Using Rhino Mocks 3.6, given the code below I would expect the AssertWasCalled assertion
I'm using Rhino 1.6r2 through the javax.script API. I know that the Rhino engine
I need to automate tests of our javascript files using Rhino and Jasmine. We
I'm working on a simple CRUD application based on vert.x platform. I'm using Rhino/JavaScript
I have just started using Rhino mocks and I am having difficulty doing that.
I am using Rhino.Security repository to manage my users/roles. The process of creation, deletion
I'm using Rhino's context.evaluateString() to run some simple JavaScript from inside of Java. It's
I'm using Rhino 1.7R4 and env.js 1.2 to run Javascript code inside Java I
My application is using Rhino.Commons - NHRepository and UnitOfWork. I like the With.Transaction() syntax

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.