Anand
Anand

Reputation: 2319

Include output of minify maven plugin in JAR

Background: I'm building a JS library, which I'm packaging as a JAR file using maven. I'm using the minify maven plugin to merge and minify the JS files.

Problem: The minify maven plugin works perfectly when I use it within a webapp packages as a WAR. But in my case, where I have a JAR packaging, the merged and minified JS output is not packaged into the JAR file. I tried explicitly configuring the resources to be included in the build, but this works for resources under src (say src/main/resources), but not for resources that are already in the target folder.

This doesn't work:

<resources>
    <resource>
        <directory>${basedir}/target/${project.build.finalName}/resources</directory>
        <includes>
            <include>**/*.js</include>
        </includes>
    </resource>
</resources>

I get a warning saying:

"[WARNING] JAR will be empty - no content was marked for inclusion!"

Question: I want to package the minified JS files within the JAR, in the META-INF/resources How do I include the output of minify-maven-plugin which is in the target folder into the JAR? folder.

Update: The minify maven plugin by default outputs the minified files to the target folder. I could optionally set a specific directory (within target) under which I want the output to be in. The minify:minify goal of the plugin takes an optional parameter 'jsTargetDir'. The issue persists even when I set my original source JS as a resource. The source JS files get packaged into the JAR, but not the minified ones. The JAR plugin and Resource plugins of maven recognize only files under src. Since the minified files are not under src, but directly under target, mvn package doesn't seem to recognize those files.

Thanks,

Anand

Upvotes: 3

Views: 1962

Answers (1)

Samuel Santos
Samuel Santos

Reputation: 401

You need to set the option webappTargetDir which by default points to ${project.build.directory}/${project.build.finalName}.

Upvotes: 1

Related Questions