Archive for the ‘Maven’ Category

Eclipse
Solve ClassNotFoundExceptions with Maven war projects on Eclipse

August 31st, 2012

When working on Maven web projects with Eclipse, m2e and m2e-wtp, Webapps can sometimes suddenly stop working, raising ClassNotFoundExceptions on every startup.

This is because the webapp lib folder is no longer published to the server. Cleaning, Publishing, Closing/opening project, restarting Eclipse, nothing restore this folder and its content. Additionally, a new warning appears in the problem view :

Classpath entry org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER will not be exported or published

To solve this issue, just open .classpath at the root of the project and add the following attribute to the maven classpath :

<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>

Save and publish to the server.

The webapp should start again.

Source: Post from Eclipse forums http://www.eclipse.org/forums/index.php/t/262101/

Java
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>

Java
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…)

Java
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.

Maven
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.