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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:01:32+00:00 2026-05-19T10:01:32+00:00

I have a web project that’s built with Maven and I’m trying to figure

  • 0

I have a web project that’s built with Maven and I’m trying to figure out the best way to compile the JavaScript files with the RequireJS compiler (this question could apply to any compiler/minifier as well).

I have a setup that works, but it needs improvement:

I’ve packaged the 3rd party JavaScript libraries and they are being downloaded as dependencies and then added with the WAR Overlay plugin.

I have an Exec plugin task that runs the RequireJS compiler inside the target directory. I currently manually run exec:exec after the package target runs (and therefore the WAR contents are placed in the target directory).

What I would like instead is to make JS compilation part of main (Java) compilation. The JS compiler itself (Require JS) is downloaded as a dependency during the WAR overlay phase which happens after compilation. So, I need the Require JS files to be downloaded and unpacked and I need to run the JS compilation using those files, before/during/after Java compilation.

I’m sure there could be several ways to achieve this. I’m looking for the most elegant solution.


Update: Existing POM snippets

I have JavaScript dependencies which I have zipped and added to our repository manager:

    <dependency>
        <groupId>org.requirejs</groupId>
        <artifactId>requirejs</artifactId>
        <version>0.22.0</version>
        <classifier>repackaged</classifier>
        <type>zip</type>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.jqueryui</groupId>
        <artifactId>jquery-ui</artifactId>
        <version>1.8.7</version>
        <classifier>repackaged</classifier>
        <type>zip</type>
        <scope>runtime</scope>
    </dependency>

Take note that RequireJS itself (which is required for the compilation of the rest of libraries) is also loaded as an external dependency. So the first thing is, I need this dependency to be downloaded and unzipped before I can commence with RequireJS compilation.

These dependencies are being added to the WAR using the WAR Overlay plugin:

        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <overlays>
                    <overlay>
                        <groupId>org.requirejs</groupId>
                        <artifactId>requirejs</artifactId>
                        <classifier>repackaged</classifier>
                        <type>zip</type>
                        <targetPath>lib</targetPath>
                        <includes>
                            <include>requirejs/require.js</include>
                            <include>requirejs/require/*</include>
                            <include>requirejs/build/**</include>
                        </includes>
                    </overlay>
                    <overlay>
                        <groupId>com.jqueryui</groupId>
                        <artifactId>jquery-ui</artifactId>
                        <classifier>repackaged</classifier>
                        <type>zip</type>
                        <targetPath>lib</targetPath>
                    </overlay>
                </overlays>
            </configuration>
        </plugin>

Even though I don’t need requirejs/build/** to end up in the WAR, I’m including it as part of the overlay to get the unzipped RequireJS build scripts, simply because I haven’t figured out a better way.

Then I have a Exec plugin task that performs the compilation. But note that this task hasn’t been added to the normal compilation work flow: I have to manually invoke it with mvn exec:exec after the WAR packaging is done:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>lib/requirejs/build/build.bat</executable>
                <workingDirectory>${project.build.directory}/${project.artifactId}</workingDirectory>
                <arguments>
                    <argument>name=bootstrap</argument>
                    <argument>out=combined.js</argument>
                    <argument>baseUrl=scripts</argument>
                    <argument>optimize=closure</argument>
                    <argument>excludeShallow=plugins/manifest</argument>
                </arguments>
            </configuration>
        </plugin>

So, some questions are:

  1. How can I extract different portions of a single zipped dependency for the compilation and WAR packaging steps? Or do I have to create two zip files, one with just the runtime stuff and the other for compilations scripts?
  2. I would like to trigger exec:exec ideally during compilation, or if not, just prior to WAR packaging. How do I do that?

I have actually tried a bunch off stuff without success, so I hope I don’t appear as lazily posting a huge chunk of code and waiting for answers 🙂 It’s just that I haven’t quite wrapped my mind around how Maven targets/phases etc. work yet.

  • 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-19T10:01:32+00:00Added an answer on May 19, 2026 at 10:01 am

    I’ve come up with the following solution that works for me:

    Instead of depending on the WAR overlay for the unpacking of the RequireJS files, I explicitly unpack them using the Dependency plugin:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.requirejs</groupId>
                  <artifactId>requirejs</artifactId>
                  <version>0.22.0</version>
                  <type>zip</type>
                  <classifier>repackaged</classifier>
                  <overWrite>true</overWrite>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
    

    The phase is set to “compile”. This allows me to have the entire contents of the RequireJS package under the “dependency” folder, during compilation. So, the next thing I have is:

          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
              <execution>
                <phase>compile</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>
                  ${project.build.directory}/dependency/requirejs/build/build.bat</executable>
                  <workingDirectory>
                  ${basedir}/src/main/webapp</workingDirectory>
                  <arguments>
                    <argument>name=bootstrap</argument>
                    <argument>out=scripts/compiled.js</argument>
                    <argument>baseUrl=scripts</argument>
                    <argument>optimize=closure</argument>
                    <argument>
                    excludeShallow=plugins/manifest</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
    

    This triggers RequireJS compilation inside the “dependency” folder, without touching either my source directory or the WAR directory. I then continue using the WAR overlay plugin to cherry pick the RequireJS files that want to go into the WAR.

    Update

    Since writing this solution, I’ve switched to using the “java” goal instead of “exec” because I had problems with using the RequireJS compiler’s shell script + batch file through Hudson. I’m basically running the final Java command (generated by the scripts) that run the compiler through Rhino. The Node solution would be slightly different. For RequireJS 0.23.0, it goes something like this:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
            <execution>
                <id>compile-js</id>
                <phase>compile</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
                <configuration>
                    <executable>java</executable>
                    <workingDirectory>${basedir}/src/main/webapp</workingDirectory>
                    <arguments>
                        <argument>-classpath</argument>
                        <!--argument>${project.build.directory}/dependency/requirejs/build/lib/rhino/js.jar${path.separator}${project.build.directory}/dependency/requirejs/build/lib/closure/compiler.jar</argument -->
                        <argument>${project.build.directory}/dependency/requirejs/build/lib/rhino/js.jar</argument>
                        <argument>org.mozilla.javascript.tools.shell.Main</argument>
                        <argument>${project.build.directory}/dependency/requirejs/bin/x.js</argument>
                        <argument>${project.build.directory}/dependency/requirejs/bin/</argument>
                        <argument>${project.build.directory}/dependency/requirejs/build/build.js</argument>
                        <argument>name=bootstrap</argument>
                        <argument>out=scripts/compiled.js</argument>
                        <argument>baseUrl=scripts</argument>
                        <argument>optimize=none</argument>
                    </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web project that I am ripping out all the inline styling
I have a maven web project that imported into eclipse. I have another maven
I have a web service project that has 2 asmx files. Let’s call them
I have a large vb.net web project that I am trying to updgrade to
I have been trying to convert a web project that produces a war file
I have a web application that I'm trying to create a Web Deployment Project
This should be simple but can't figure it out. I have a web project
I have a web application project that works with a quite large database (over
I have inherited a web project that is perl based and I'm attempting to
I have a google web application project that I want to host on github.

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.