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 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

Title says all. I'll have navigation that looks like this and it's dynamically created
As the title says, I'm trying to do something like this: public abstract class
As title says, how do I call a java class method from a jsp,
As title says I'd like to know how to restart my iPhone app after
As the title says I'd like to somehow get the cache behavior of my
Like the title says, I want to parse XML in my iPhone application, but
As title says, mock code to demostrate my problem Driver Class import java.io.*; public
Like the title says, how do I redirect every url that starts with http://example.com/shop
As the title says, will this code work and will it work in major
As the question's title says, I want to get the system information (like OS

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.