Wednesday, February 1, 2012

Struts1 - Install

We need the struts.jar, struts-taglib.jar and all the jars they depend on.

So update your ivy.xml to declare dependency on these jars, like this:

(Note that I had to manually include the other dependencies because of the way my repository is structured - you won't need to if you are pointing to the Maven central repository)

 <ivy-module version="2.0">  
   <info organisation="org.confucius" module="helloworld"/>  
   <dependencies>  
           <dependency org="struts" name="struts" rev="1.2.9"/>  
           <dependency org="org.apache.struts" name="struts-taglib" rev="1.3.10"/>            
           <dependency org="commons-collections" name="commons-collections" rev="20040616"/>  
           <dependency org="commons-digester" name="commons-digester" rev="2.1"/>  
           <dependency org="commons-beanutils" name="commons-beanutils" rev="20030211.134440"/>  
           <dependency org="commons-logging" name="commons-logging" rev="1.1.1"/>  
           <dependency org="org.apache.httpcomponents" name="httpcore" rev="4.2-alpha2"/>            
           <dependency org="org.apache.httpcomponents" name="httpclient" rev="4.2-alpha1"/>             
           <dependency org="org.apache.commons" name="commons-exec" rev="1.1"/>        
           <dependency org="com.google.guava" name="guava" rev="r09"/>  
           <dependency org="org.seleniumhq.selenium" name="selenium-api" rev="2.17.0"/>  
           <dependency org="org.seleniumhq.selenium" name="selenium-remote-driver" rev="2.17.0"/>  
           <dependency org="org.seleniumhq.selenium" name="selenium-firefox-driver" rev="2.17.0"/>  
           <dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.16.1"/>            
           <dependency org="junit" name="junit" rev="4.10"/>            
           <dependency org="org.json" name="json" rev="20090211"/>  
     <dependency org="javax.servlet" name="servlet-api" rev="2.5"/>  
     <dependency org="javax.servlet" name="jsp-api" rev="2.0"/>  
     <dependency org="jstl" name="jstl" rev="1.2"/>  
         <dependency org="log4j" name="log4j" rev="1.2.16"/>   
   </dependencies>  
 </ivy-module>  


Run the Ant 'resolve' target to download these jars to your /lib folder.

Now we need to include these jars in the Eclipse Classpath.
Go to Project->Properties->Java Build Path->Libraries->Add Jars

and add all the jars you downloaded.

We also need to include these jars in the Classpath of Ant build.xml, like this:

 <project name="HelloWorld" xmlns:ivy="antlib:org.apache.ivy.ant" >  
   
   <target name="resolve" description="--> retrieve dependencies with ivy">  
     <ivy:retrieve />  
   </target>  
   
      <target name="init" depends="resolve">  
           <mkdir dir="classes"/>  
           <mkdir dir="target"/>  
      </target>  
   
      <path id="build.classpath">  
       <pathelement location="lib/commons-collections-20040616.jar"/>  
       <pathelement location="lib/commons-digester-2.1.jar"/>  
       <pathelement location="lib/commons-beanutils-20030211.134440.jar"/>  
       <pathelement location="lib/struts-taglib-1.3.10.jar"/>  
       <pathelement location="lib/struts-1.2.9.jar"/>  
       <pathelement location="lib/commons-logging-1.1.1.jar"/>  
       <pathelement location="lib/httpcore-4.2-alpha2.jar"/>  
       <pathelement location="lib/httpclient-4.2-alpha1.jar"/>  
       <pathelement location="lib/commons-exec-1.1.jar"/>  
       <pathelement location="lib/guava-r09.jar"/>  
       <pathelement location="lib/selenium-api-2.17.0.jar"/>  
       <pathelement location="lib/selenium-firefox-driver-2.17.0.jar"/>  
       <pathelement location="lib/selenium-java-2.16.1.jar"/>  
       <pathelement location="lib/selenium-remote-driver-2.17.0.jar"/>  
       <pathelement location="lib/junit-4.10.jar"/>  
       <pathelement location="lib/json-20090211.jar"/>  
       <pathelement location="lib/servlet-api-2.5.jar"/>  
       <pathelement location="lib/jsp-api-2.0.jar"/>  
       <pathelement location="lib/log4j-1.2.16.jar"/>  
      </path>  
   
      <target name="compile" depends="init">  
           <javac srcdir="." destdir="classes">  
                <classpath refid="build.classpath"/>  
           </javac>  
      </target>  
   
      <path id="test.classpath">  
       <pathelement location="classes"/>  
       <pathelement location="lib/junit-4.10.jar"/>  
       <pathelement location="lib/selenium-api-2.17.0.jar"/>  
       <pathelement location="lib/selenium-firefox-driver-2.17.0.jar"/>  
       <pathelement location="lib/selenium-java-2.16.1.jar"/>  
       <pathelement location="lib/selenium-remote-driver-2.17.0.jar"/>  
       <pathelement location="lib/guava-r09.jar"/>  
       <pathelement location="lib/commons-exec-1.1.jar"/>  
       <pathelement location="lib/httpclient-4.2-alpha1.jar"/>  
       <pathelement location="lib/httpcore-4.2-alpha2.jar"/>  
       <pathelement location="lib/commons-logging-1.1.1.jar"/>  
       <pathelement location="lib/struts-1.2.9.jar"/>  
       <pathelement location="lib/struts-taglib-1.3.10.jar"/>  
       <pathelement location="lib/commons-beanutils-20030211.134440.jar"/>  
       <pathelement location="lib/commons-digester-2.1.jar"/>  
       <pathelement location="lib/commons-collections-20040616.jar"/>  
      </path>  
   
      <target name="test" depends="compile" >  
           <junit failureproperty="junit.failure">  
                <test name="org.confucius.TestCalculator"/>  
                <classpath refid="test.classpath"/>  
                <formatter type="plain" usefile="false" />  
           </junit>  
           <fail if="junit.failure" message="Unit test(s) failed. See reports!"/>  
      </target>  
        
      <target name="dist" depends="test">  
           <war destfile="target/HelloWorld.war" webxml="web.xml">  
                 <classes dir="classes"/>  
                 <lib dir="lib">  
                      <exclude name="jsp-api*.jar"/>  
                      <exclude name="servlet-api*.jar"/>  
                 </lib>       
                 <fileset dir="web-content"/>  
                 <webinf dir="WEB-INF"/>  
           </war>  
           <echo>Build executed at ${TIME_NOW}</echo>  
      </target>  
   
      <tstamp>   
           <format property="TIME_NOW" pattern="hh:mm:ss aa MM/dd/yyyy"/>   
      </tstamp>   
        
 </project>  



You are now ready to use Struts1.

No comments: