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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:08:23+00:00 2026-06-01T10:08:23+00:00

I have a java enum that is used in my web application. I also

  • 0

I have a java enum that is used in my web application. I also have a lot of javascript code that refers to the values of the enum. It would be ideal If I could generate a javascript file from the enum as part of the maven build process. Does anyone know of a project that solves this problem or of an elegant way to tackle it ?
Thanks!

  • 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-01T10:08:25+00:00Added an answer on June 1, 2026 at 10:08 am

    It turns out that there is a great way to do it using a groovy maven plugin as a “prepare-package” phase.
    This is the code :
    In your pom.xml add this entry :

    <plugin>
                    <groupId>org.codehaus.groovy.maven</groupId>
                    <artifactId>gmaven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>script-prepare-package1</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>execute</goal>
                            </goals>
                            <configuration>
                                <source>${basedir}/src/main/groovy/GenerateJavaScriptEnum.groovy</source>
                            </configuration>
                        </execution>
    
                    </executions>
                </plugin>
    

    This is how the groovy script, GenerateJavaScriptEnum.groovy, looks like :

        def fields = []
    
    
    com.foo.bar.YourEnum.values().each() { f->
        fields << "${f.name()} : \"${f.getId()}\""
    }
    
    if (fields) {
        log.info("Generating Javascript for com.foo.bar.YourEnum")
    
        [
                new File("${project.build.directory}/${project.build.finalName}/js"),
                new File("${project.basedir}/src/main/webapp/js")
        ].each() { baseOutputDir->
            if (!baseOutputDir.exists()) {
                baseOutputDir.mkdirs()
                log.info("Created output dir ${baseOutputDir}")
            }
    
            def outfile = new File(baseOutputDir, "YourEnum.js")
    
            log.info("Generating ${outfile}")
    
            def writer = outfile.newWriter("UTF-8")
            writer << "// FILE IS GENERATED FROM com.foo.bar.YourEnum.java.\n"
            writer << "// DO NOT EDIT IT.  CHANGES WILL BE OVERWRITTEN BY THE BUILD.\n"
            writer << "YourEnum = {\n"
            writer << fields.join(",\n")
            writer << "\n}"
            writer.close()
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java singleton class that has my application settings. I used this
I have a client jar made-up using java 1.6 and used enum and other
I have a Java Web Start application calling remote Java EE 5 EJBs to
I have a handful of helper methods that convert enum values into a list
I'm writing a Java application that needs a lot of static data that is
I have the follwoing enum in my backend java code: public static enum CountryCodes
I have some old code (pre Java 1.5) that uses classes to implement type
Possible Duplicate: Java - Convert String to enum I have a method that uses
I have a contant list declared in java using enum type, that must appears
I have a java application that I made and this week I tried to

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.