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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:29:51+00:00 2026-06-13T00:29:51+00:00

I’m writing a couple of library classes that I am sharing between several projects.

  • 0

I’m writing a couple of library classes that I am sharing between several projects. Some of these projects are plain-old Java and others are GWT applications. For some of these classes the exact implementation is different whether they need to run in GWT or in Java (Let’s not get into exactly why, but just as one of many examples, Date.getMonth is deprecated in Java, but the Calendar replacement isn’t available in GWT).

Is there a way to mark certain sections of code as pertaining to one or the other scenario?

I looked at using deferred binding and class-replacement in GWT, but that requires instantiation of classes using GWT.create() which isn’t available for a plain-old Java app and will therefore lead to compile errors.

  • 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-13T00:29:53+00:00Added an answer on June 13, 2026 at 12:29 am

    Found a solution that works beautifully: the <super-source> tag in my library’s .gwt.xml file!

    Basically, I have two versions of the following EnvironmentFlags class in my library. One in the actual library that is used by Java located in folder “lib“:

    my.library.EnvironmentFlags looks like this:

    package my.library;
    
    public class EnvironmentFlags {
      public static final boolean IS_GWT      = false;
      public static final boolean IS_DEV_MODE = false;
    }
    

    And then a file in the folder “super/my/library” that looks like this:

    package my.library;
    
    import com.google.gwt.core.client.GWT;
    
    public class EnvironmentFlags {
      public static final boolean IS_GWT      = true;
      public static final boolean IS_DEV_MODE = !GWT.isProdMode();
    }
    

    Now the magic: The .gwt.xml file of my library looks like this:

    <module>
      <source       path='lib'   />
      <super-source path='super' />
    </module>
    

    This leads to plain-old Java using the first version of the EnvironmentFlags class, which simply sets both flags to false, while the GWT compiler replaces the source of that class with the second version loaded from the super-source directory, which sets the GWT flag to true and the DEV_MODE flag to whatever it gets from GWT.

    Now, in my code I can simply use the following:

    if (EnvironmentFlags.IS_GWT) {
      // Do GWT stuff
    } else {
      // Do plain-old Java stuff
    }
    

    and both, the Java and the GWT compiler should drop the respective unreachable/unneeded code from the compiled result, i.e. no run-time overhead needed.

    PS: The IS_DEV_MODE flag doesn’t actually have anything to do with my original question. I just included it as a freebie which allows me to have my code act differently (more verbose, for example) depending on whether I am testing or deploying my GWT app.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this

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.