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 6110961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:34:33+00:00 2026-05-23T14:34:33+00:00

As the title says, I’d like to pass defines programmatically via the Java API

  • 0

As the title says, I’d like to pass defines programmatically via the Java API to the Google Closure Compiler.

This is my current code:

com.google.javascript.jscomp.Compiler.setLoggingLevel(Level.INFO);
com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
CompilerOptions options = new CompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
WarningLevel.VERBOSE.setOptionsForWarningLevel(options);

List<JSSourceFile> externs = new ArrayList<JSSourceFile>();
externs.add(JSSourceFile.fromFile(extern_src));

List<JSSourceFile> primary = new ArrayList<JSSourceFile>();
primary.add(JSSourceFile.fromFile(tmp));
compiler.compile(externs, primary, options);
for (JSError message : compiler.getWarnings()) {
    System.err.println("Warning message: " + message.toString());
}

for (JSError message : compiler.getErrors()) {
    System.err.println("Error message: " + message.toString());
}
  • 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-23T14:34:34+00:00Added an answer on May 23, 2026 at 2:34 pm

    You want to populate the define replacements map.

    options.getDefineReplacements().put("myDefineVarName", value);
    

    The value has to be a Node that is a boolean, numeric, or string literal.
    To create a value for a boolean literal use a value like

    new Node(Token.TRUE)
    

    where both Node and Token are from the package com.google.javascript.jscomp.rhino.

    I believe Token.STRING and Token.NUMBER are the token types for the other kinds of values but don’t quote me on that.

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

Sidebar

Related Questions

As title says, how do I call a java class method from a jsp,
Like the title says Where and How (i.e. if encrypted, with what method) does
Like the title says, how do you create custom code snippets in Visual Studio
As title says, this issue happens in MS Access 2003 SP1. Does anyone know
As title says, I have a yaml file with values like development: email:dev@abc.com test:
The title says most of what I'd like to accomplish. I'd like to render
like the title says, I am trying to create a drop down menu using
As the title says, is deploying/using applications through Java Web Start a viable option?
As the title says: in sharepoint 2010 i need to programmatically create a view
As the title says, i need a way to programmatically edit an existing view

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.