09 декември 2010, четвъртък

Richfaces Maven Resource Dependency Plugin without Maven

Introduction


What we have in my company is a Richfaces web application. While looking for optimization tips I found Maven Resource Dependency Plugin. Looks great, but our project uses Ant for a build tool and I had never used Maven before. Still I wanted to optimize the resource loading in the web application.

Solution


After some googling I found that the existing project structure can be applied in tha Maven's pom.xml. I followed the instructions from the documentation and the Richfaces and Maven integration documentation.
Here is my pom.xml located in the build/ folder.

<project  ... >
 <modelVersion>4.0.0</modelVersion>
...

// We need the three richfaces jars as dependencies, since the plugin
// gets the js and the css from there
 <dependencies>
  <dependency>
   <groupId>org.richfaces.framework</groupId>
   <artifactId>richfaces-api</artifactId>
   <version>3.3.3-Final</version>
   <scope>system</scope>
   <systemPath>${basedir}/../WebContent/WEB-INF/lib/richfaces-api-3.3.3.Final.jar</systemPath>
  </dependency>
// The same for the impl and ui
...
 </dependencies>
 <repositories>
// Put the jboss richfaces repositories (http://repository.jboss.com/maven2/ and
// http://snapshots.jboss.org/maven2/) here
 </repositories>

 <pluginRepositories>
// Put the above repositories here as plugin repositories
 </pluginRepositories>

 <build>
  <plugins>
   <plugin>
    <artifactId>maven-resource-dependency-plugin</artifactId>
    <groupId>org.richfaces.cdk</groupId>
    <version>3.3.4-SNAPSHOT</version>
    <configuration>
     <webSourceDirectory>../WebContent/WEB-INF/</webSourceDirectory>
     <outputResourceDirectory>../src/res</outputResourceDirectory>
     <styleFilePath>richfaces.xcss</styleFilePath>
     <scriptFilePath>richfaces.js</scriptFilePath>
    </configuration>
   </plugin>
  </plugins>
 </build>
</project>


To call Maven from Ant, just downloaded maven-ant-tasks.jar and defined in build.xml

<path id="maven-ant-tasks.classpath" path="${build.lib.dir}/maven-ant-tasks-2.1.1.jar" />
 <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
  uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" />


 <target name="GenerateResourceDependencies">
  <artifact:mvn pom="${build.dir}/pom.xml">
   <arg value="resource-dependency:assembly-resources" />
  </artifact:mvn>
 </target>


The final issue was that for some reason I had to add '3_3_3.Final in the path to the generated resources.


    <link href="#{request.contextPath}/ws/a4j/3_3_3.Final/res/richfaces.xcss" rel="stylesheet"
        type="text/css" />
    <script src="#{request.contextPath}/ws/a4j/3_3_3.Final/res/richfaces.js"
        type="text/javascript" />


If you use the skinning of the html controls (buttons, fields, etc) you need to add in your header also


<link class="component"
      href="#{request.contextPath}/ws/a4j/3_3_3.Finalorg/richfaces/renderkit/html/css/basic_both.xcss"
      rel="stylesheet" type="text/css" />

   <link class="component"
      href="#{request.contextPath}/ws/a4j/3_3_3.Finalorg/richfaces/renderkit/html/css/extended_both.xcss"
      media="rich-extended-skinning" rel="stylesheet" type="text/css" />

   <script type="text/javascript">window.RICH_FACES_EXTENDED_SKINNING_ON=true;</script>

   <script
      src="#{request.contextPath}/ws/a4j/3_3_3.Finalorg/richfaces/renderkit/html/scripts/skinning.js"
      type="text/javascript"></script>

Conclusion


Maven is a great tool :)

Няма коментари:

Публикуване на коментар