Archive for the ‘Maven’ Category

Transparent javascript and css compression with Maven3 and Yuicompressor

December 23rd, 2011

There are a lot of ressources on how to use YUIcompressor on a Maven project, but several examples don’t work with Maven3, or don’t allow to replace javascript and css by their compressed version transparently.

The following example will compress files transparently when packaging the webapp in a WAR file, and keep original files for development.

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-war-plugin</artifactId>
   <version>2.1.1</version>            
   <configuration>
      <warSourceExcludes>**/*.css,**/*.js</warSourceExcludes>
   </configuration>
</plugin>


<plugin>
   <groupId>net.alchim31.maven</groupId>
   <artifactId>yuicompressor-maven-plugin</artifactId>
   <executions>
      <execution>
         <id>compressyui</id>
         <phase>prepare-package</phase>
         <goals>
            <goal>compress</goal>
         </goals>
      </execution>

   </executions>
   <configuration>
      <nosuffix>true</nosuffix>
   </configuration>
</plugin>

Set Jetty buffer size (Maven)

March 11th, 2010

Working with large cookies and jetty, you may have faced this error :

2010-03-11 18:18:31.275:WARN::HttpException(413,FULL head,null)

This is because jetty allows only 4ko for HTTP request and response headers. Using large cookies is enough to reach the limit.

(more…)

Fixing Struts2 initialization error on Jetty restart

August 12th, 2009

[ERROR] Error reconfiguring/restarting webapp after change in watched files
Caught exception while loading file struts-default.xml – [unknown location]

Caused by: java.lang.ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration

This issue seems to only occur with Java 6 and is related to the Xalan version included in this JDK.

Add xalan to your pom or in an endorsed/shared directory and the problem goes away.

<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.1</version>
</dependency>

More details there : JIRA item.

Fixing ‘could not write file’ issue with Jetty on Windows

June 12th, 2009

Xebia has published a very nice article (Maven, jetty plugin et section mappée – French) explaining how to fix the long-standing locking file issue affecting Jetty / Maven users on Windows.

On this platform, Jetty locks all .js or .css files, making it impossible to change their content while the server is still running. This is a big loss of time because you always have to stop/restart jetty to update one of these files.

Note: this issue does not occur on Linux or Mac OSX so I personnaly don’t really care, but for the ones still running on Windows, the post provides 2 possible fixes :

  • 1 – Changing the connector : this one did not work for us, Jetty was no longer starting (Class not found).
  • 2 – Overriding the defaut web context (webdefault.xml) : it does the trick, Great !

As a result, this is the steps that worked for us :

  • Get webDefault.xml from the jetty jar and add it to your project. Package is org.mortbay.jetty.webapp
  • Change useFileMappedBuffer to false :

    <servlet>
    ...
    <init-param>
    <param-name>useFileMappedBuffer</param-name>
    <param-value>false</param-value>
    </init-param>
    ...
    </servlet>

  • Add this new webDefault.xml to Jetty config :

    ...
    <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>6.1.14</version>
    <configuration>
    <webDefaultXml>
    src/main/etc/webdefault.xml
    </webDefaultXml>
    </configuration>
    </plugin>
    ...

  • Restart jetty…. files can be edited. :-)

See original post for additionnal details.

Building RCP plugins or products with Maven2

May 29th, 2009

This is something I never really took the time to try.

At first this seems rather complicated because of the duplication of dependencies in both pom.xml and MANIFEST.MF and because RCP plugins are usually not deployed to maven public repositiories.

Tycho now seems the way to go but I’m looking for advices from my readers.

How do you build RCP products with maven2 ?