maven plugin for war file

hi,

I need to create a war file through maven plugin. It should compress/minify the css and js inside before making war to reduce the size of war.

I came across the solution but it is taking specific file,is there any way in whcih we can provide the js and css paths?

Example on the above would be helpful.


<build>
  <plugins>
    <plugin>
      <groupId>com.samaxes.maven</groupId>
      <artifactId>minify-maven-plugin</artifactId>
      <version>1.7.3</version>
      <executions>
        <execution>
          <id>default-minify</id>
          <configuration>
            <charset>UTF-8</charset>
            <cssSourceFiles>
              <cssSourceFile>file-1.css</cssSourceFile>
              <!-- ... -->
              <cssSourceFile>file-n.css</cssSourceFile>
            </cssSourceFiles>
            <jsSourceFiles>
              <jsSourceFile>file-1.js</jsSourceFile>
              <!-- ... -->
              <jsSourceFile>file-n.js</jsSourceFile>
            </jsSourceFiles>
            <jsEngine>CLOSURE</jsEngine>
          </configuration>
          <goals>
            <goal>minify</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Open in new window

RockingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
The above code that you posted appears to be the first example from the plugin's website. Did you check out the second example?
<project>
  <!-- ... -->
  <build>
    <plugins>
      <!-- ... -->
      <plugin>
        <groupId>com.samaxes.maven</groupId>
        <artifactId>minify-maven-plugin</artifactId>
        <version>1.7.3</version>
        <executions>
          <execution>
            <id>default-minify</id>
            <configuration>
              <cssSourceIncludes>
                <cssSourceInclude>**</cssSourceInclude>
              </cssSourceIncludes>
              <cssSourceExcludes>
                <cssSourceExclude>**/*.min.css</cssSourceExclude>
              </cssSourceExcludes>
              <jsSourceIncludes>
                <jsSourceInclude>**</jsSourceInclude>
              </jsSourceIncludes>
              <jsSourceExcludes>
                <jsSourceExclude>**/*.min.js</jsSourceExclude>
              </jsSourceExcludes>
            </configuration>
            <goals>
              <goal>minify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <!-- ... -->
    </plugins>
  </build>
  <!-- ... -->
</project>

Open in new window

You can tailor the above patterns to correctly select all your required css, js files.
0
RockingAuthor Commented:
how to build the war from maven by using the above plugin?
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
That plugin isn't used to build the war, it is only used to minify (ie. compress) your css and js files before something else builds the war file.

So, as for building a war file you just set the <packaging> element to war and maven takes care of the rest. If you need to configure anything special though, you then might need to explicitly declare the maven-war-plugin so that you can set your configuration, but generally this is not necessary.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

RockingAuthor Commented:
Execution default-minify of goal com.samaxes.maven:minify-maven-plugin:1.7.3:minify failed: basedir D:\workspace\study\mavenWar\src\main\webapp\css does not exist


how can i change the default path since i have put the css in "WebContent/css" folder.
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Again, just as per the documentation (http://samaxes.github.io/minify-maven-plugin/minify-mojo.html) you can add a <cssSourceDir> element (and I guess the same for your js) to point to the correct folder. The doc says that the default is "css" so just add <cssSourceDir>WebContent/css</cssSourceDir> to the plugin's configuration in your pom.xml
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RockingAuthor Commented:
thanks for reply.

When i made the required modification suggested by you it shows he path like
 D:\workspace\study\mavenWar\src\main\webapp\WebContent\css

not removing webapp instead appending the source dir path to it.


i just want to minify the js and css file,as of now it is doing the same but also combining all the css into single and all js into single js.

how to avoid the combining of js & css into single?
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Also on the very same page that I just linked to above...      <skipMerge>true</skipMerge>
0
RockingAuthor Commented:
<cssSourceDir>WebContent/css</cssSourceDir>


When i made the required modification suggested by you it shows the path like
 D:\workspace\study\mavenWar\src\main\webapp\WebContent\css

not removing webapp instead appending the source dir path to it.
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
not removing webapp instead appending the source dir path to it.
Well that's because I assumed that that was what you wanted. You weren't clear when you said "WebContent/css" at what level that that folder was at.

So, again, by just reading the documentation, remove the <cssSourceDir> configuration option that I mentioned earlier (because the default "css" will work fine now) and add....    <webappSourceDir>${basedir}/src/main/WebContent</webappSourceDir>
0
RockingAuthor Commented:
It's not working still checking in the same path (D:\workspace\study\mavenWar\src\main\webapp\WebContent\css)

POM is below

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
  <groupId>mavenWar</groupId>
  <artifactId>mavenWar</artifactId>
  <version>0.0.1</version>
  <packaging>war</packaging>
  <name>test Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
 <build>
    <plugins>
  <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <executions>
            <execution>
                <id>default-war</id>
                <phase>prepare-package</phase>
                <configuration>
                <webappSourceDir>${basedir}/WebContent</webappSourceDir>
                <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <archiveClasses>false</archiveClasses>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix />
                        </manifest>
                        <manifestEntries>
                            <Implementation-Build>${build.number}</Implementation-Build>
                            <Implementation-Title>${project.name}</Implementation-Title>
                            <Built-By>${user.name}</Built-By>
                            <Built-OS>${os.name}</Built-OS>
                            <Build-Date>${build.date}</Build-Date>
                        </manifestEntries>
                    </archive>
                    <webResources>
                        <resource>
                            <!-- this is relative to the pom.xml directory -->
                            
                              <directory>${basedir}</directory>
                        </resource>
                    </webResources>
                </configuration>
            </execution>
        </executions>
    </plugin>
      <plugin>
        <groupId>com.samaxes.maven</groupId>
        <artifactId>minify-maven-plugin</artifactId>
        <version>1.7.3</version>
        <executions>
          <execution>
            <id>default-minify</id>
            <configuration>
             <skipMerge>true</skipMerge>
             <nosuffix>true</nosuffix>
              <cssSourceIncludes>
                <cssSourceInclude>**</cssSourceInclude>
              </cssSourceIncludes>
              <cssSourceExcludes>
                <cssSourceExclude>**/*.min.css</cssSourceExclude>
              </cssSourceExcludes>
              <jsSourceIncludes>
                <jsSourceInclude>**</jsSourceInclude>
              </jsSourceIncludes>
              <jsSourceExcludes>
                <jsSourceExclude>**/*.min.js</jsSourceExclude>
              </jsSourceExcludes>
            </configuration>
            <goals>
              <goal>minify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
  </build>
</project>

Open in new window

0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
It's not working still checking in the same path
Are you sure? Because I would have expected it to be back looking in the original "src/main/webapp/css" path with that pom.xml

You've removed the <cssSourceDir> element (which is what I said to do above and is correct) but you haven't added the <webappSourceDir> element that I just told you to, so it will still be looking at "src/main/webapp/css"
0
RockingAuthor Commented:
not working

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
  <groupId>mavenWar</groupId>
  <artifactId>mavenWar</artifactId>
  <version>0.0.1</version>
  <packaging>war</packaging>
  <name>test Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
 <build>
    <plugins>
  <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <executions>
            <execution>
                <id>default-war</id>
                <phase>prepare-package</phase>
                <configuration>
                <webappSourceDir>${basedir}/src/main/WebContent</webappSourceDir>
                <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <archiveClasses>false</archiveClasses>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix />
                        </manifest>
                        <manifestEntries>
                            <Implementation-Build>${build.number}</Implementation-Build>
                            <Implementation-Title>${project.name}</Implementation-Title>
                            <Built-By>${user.name}</Built-By>
                            <Built-OS>${os.name}</Built-OS>
                            <Build-Date>${build.date}</Build-Date>
                        </manifestEntries>
                    </archive>
                    <webResources>
                        <resource>
                            <!-- this is relative to the pom.xml directory -->
                            
                              <directory>${basedir}</directory>
                        </resource>
                    </webResources>
                </configuration>
            </execution>
        </executions>
    </plugin>
      <plugin>
        <groupId>com.samaxes.maven</groupId>
        <artifactId>minify-maven-plugin</artifactId>
        <version>1.7.3</version>
        <executions>
          <execution>
            <id>default-minify</id>
            <configuration>
             <skipMerge>true</skipMerge>
             <nosuffix>true</nosuffix>
              <cssSourceIncludes>
                <cssSourceInclude>**</cssSourceInclude>
              </cssSourceIncludes>
              <cssSourceExcludes>
                <cssSourceExclude>**/*.min.css</cssSourceExclude>
              </cssSourceExcludes>
              <jsSourceIncludes>
                <jsSourceInclude>**</jsSourceInclude>
              </jsSourceIncludes>
              <jsSourceExcludes>
                <jsSourceExclude>**/*.min.js</jsSourceExclude>
              </jsSourceExcludes>
            </configuration>
            <goals>
              <goal>minify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
  </build>
</project>

Open in new window

0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You've gone and put the <webappSourceDir> element in the "maven-war-plugin" configuration instead of in the "minify-maven-plugin" that we have been talking about.

And to save a bit of back and forth, because I am guessing that your next question will be how to get the "maven-war-plugin" to look at the right location too, funnily enough, it has documentation too... http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html    which if you have a look you will see that you can add a <warSourceDirectory> option to the "maven-war-plugin" configuration so that IT knows exactly where to look. You would give this the same value, so...

<warSourceDirectory>${basedir}/src/main/WebContent</warSourceDirectory>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Applications

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.