Friday, December 16, 2011

Compressing Javascript and CSS using YUI and ANT

Before we look into more specifics you will have to download these two:
1. YUICompression jar from the Yahoo developer site: http://yuilibrary.com/download/yuicompressor/
2. YUIAnt jar file from http://www.ubik-ingenierie.com/miscellanous/YUIAnt/


Place the YUIAnt.jar and YUICompression jar into the lib directory of the project.


build.xml:



<property name="tools.lib.dir" value="tools"/>
<property name="jsmin.dir" value="jsmin"/>
<target name="cleanJSMin" description="Remove all generated files.">
    <delete dir="${jsmin.dir}"/>
</target>
<target name="minify" depends="cleanJSMin" description="Minifiy a set of files">
    <taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
        <classpath>
            <pathelement path="${tools.lib.dir}/yuicompressor-2.4.7.jar"/>
            <pathelement path="${tools.lib.dir}/YUIAnt.jar"/>
            <pathelement path="${tools.lib.dir}/rhino-1.6R7.jar"/>
        </classpath>
    </taskdef>
    <yuicompress linebreak="16000" warn="false" munge="no" preserveallsemicolons="true"
     outputfolder="${jsmin.dir}">
        <fileset dir="${basedir}/WebContent">
            <include name="js/jsp/*.js"/>
            <include name="js/princess/*.js"/>
            <include name="**/*.css"/>
        </fileset>
    </yuicompress>
</target>


                 
     


The reason why I prefer to minify the js and css files into a temporary directory is because we use Jenkins. If we minified the js and css files in the same location, when Jenkins update from SVN, the build will fail because of conflicts. So the solution is put the js and css into a temporary directory then copy them over to the war file.

Friday, April 8, 2011

How to set CATALINA_HOME/PATH variables in Windows

1. Download  apache-tomcat-6.x.x.zip and unzip to C:\Apache\Tomcat. This should result in C:\Apache\Tomcat\apache-tomcat-6.x.x
2. Right click on the My Computer and select properties
3. Click Advanced Tab
4. Click Environment Variables
5. Under System Variables, click New
6. In the Variable name field, enter CATALINA_HOME
7. In the Variable value field, enter the path to where the Tomcat is installed


8. Under System Variables,  look for Path and click Edit
9. In the Variable value, add %CATALINA_HOME%\bin;


10. Click OK
11. Click Apply

How to set JAVA_HOME / PATH variables in Windows

1. Right click on the My Computer and select properties
2. Click Advanced Tab
3. Click Environment Variables
4. Under System Variables, click New
5. In the Variable name field, enter JAVA_HOME
6. In the Variable value field, enter the path to where the JDK is installed


7. Under System Variables,  look for Path and click Edit
8. In the Variable value, add %JAVA_HOME%\bin;


9. Click OK
10. Click Apply

Jasper Report with embedded SQL using Struts2 + Spring Framework

We have decided that in order to make our Jasper Reports portable we need to start embedding SQL queries in our JasperReports. The plan is for all future Jasper Reports with embedded SQL queries be deployed to a dedicated JasperServer. This way the applications do not hang when someone runs a huge report; this will prevent hair being pulled out of frustration.

Our environment uses Struts 2-Spring-Hibernate + Jasper for reporting. The challenge is how to pass the connection to the JasperReports.


So here is the solution I came up with:


1. Make sure that the dataSource is declared in Spring.



2. Add a DataSource variable to the Action. In this example I autowired the datasource; it can also be mapped declaratively. 


3. Add a Connection variable in the Action and a getter. The connection will be set when the method that will return the Report is called.


4. In the struts.xml, provide the connection parameter name with the name of the connection variable in the action class. 








Tuesday, March 29, 2011

Installed JRE memory settings in Eclipse

When an application requires more memory than allocated, you may modify the memory settings of the installed JRE


Window - Preferences - Java - Installed JREs - target JRE - Edit 

Depending on how much physical memory your machine has, you may set the following arguments in the Default VM Arguments field:




-Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m