Monthly Archives: March 2012

MyFace implementation in Glassfish 3.1.1

Maybe I wasn’t searching enough, but I had agonizing experience by dealing with two JSF implementations in Dynamic Web Project in the Eclipse. Glassfish comes with Mojarra by default and it will conflict with other JSF implementation. By removing jsf-api.jar and jsf-impl.jar from Glassfish modules folder will break the project in the Eclipse. If I run the Glassfish outside of Eclipse, it may work, but I am using it within the Eclipse environment.

Solution to this problem was to modify the sun-web.xml file.

<sun-web-app error-url="">
<context-root>/DeleteThis</context-root>
<class-loader delegate="false"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class java code.</description>
</property>
</jsp-config>
<property name="useBundledJsf" value="true"/> 
 <property name="useMyFaces" value="true" />
</sun-web-app>

* Make sure to change the quote when Copy & Paste into the Eclipse

Maybe useBundledJsf is newer property, but both works fine. By setting class-loader delegate false, it tells Glassfish that the project will use other implementation instead of Sun RI.

Also, I came across another solution – from MyFace wiki. By creating in your webapp a “fake” com.sun.faces.config.ConfigureListener that will be loaded BEFORE the sun RI one’s.

/**
This class is here to prevent from using the real one from the sun reference implementation
*/
public class ConfigureListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent servletContextEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
//To change body of implemented methods use File | Settings | File Templates.
}
}

I haven’t done above solution. Basically, modifying sun-web.xml will work just fine.

Advertisements

Cygpath utility issue

So, I got the Cygwin started without any issue. However, when I execute the command to compile java code, it complains NoClass Def Found exception. Cygwin can’t find ant.jar in the classpath. I looked at the classpath, it was defintely wrong. Previous “.” was translated into “c;” and all other directories are prefixed with Cygwin home directory.

I found that there are some issues with new version of Cygwin utility command “cygpath”. I used –path –windows to convert the CLASSPATH to Cygwin format, but it didn’t work. Only solution that I found was to use two steps approach. First, convert CLASSPATH to Unix path, then convert Unix path to Windows path.

Environment.function.sh

function Classpath.build()
{
local aPath=$1
local tempPath=””

osType=$(uname -s)
#
# Now make sure it is converted to work with Cygwin
#
case ${osType} in
CYGWIN* )
# This is required since Java is running in windows and not CYGWIN
tempPath=”$(cygpath –path –unix ${aPath})”
pathValue=”;$(cygpath –path –mixed ${tempPath})”
;;
* )
pathValue=”:${aPath}”
;;
esac

echo “${pathValue}”
}

This works beautifully and now all the jar files are loaded into the CLASSPATH.

* in front of path and unix are double dash

Cygwin upgrade

We have an old version of Cygwin 1.2.x. I downloaded newer version of Cygwin and installed. Package manager was little bit tricky. By default, it didn’t download all plugins. Especially, at first, it was even missing “mintty.exe”, which allows Cygwin to open a terminal window. Also, after executed “mkpasswd -l > /etc/passwd” command, it didn’t generate the my account folder under Cygwin home. Eventually, I re-install older version of Cygwin and everything worked fine under the old version of Cygwin. After I went through old version uninstallation and re-installation of new version by manually checking “mintty, it started to show the terminal console.

There was another issue after that. New Cygwin complained about ‘\r’ character from the existing Shell Scripts. I looked at Cygwin help page and found out that it was due to DOS vs. Unix file type difference. All existing Shell scripts have ‘\r’ character at the end of line.

tr -d ‘\r’ < existing_script_file > new_script_file

Another issue was that these scripts are scattered in different file locations. They are more than 50, but less than 100. I don’t want to navigate to each folder and execute the script. I had to write a script to loop through files and remove ‘\r’. I haven’t officially studied Shell script previously, so it was extra challenge for me. Eventually, I got it working with below script.

#!/bin/bash
# Shell to read source file and remove ‘\r’ character from sh script
# First thing that you want to do is convert .bash_profile by executing below command manually in Cygwin
#
# tr -d ‘\r’ < .bash_profile > .bash_profile_unix
# mv .bash_profile_unix .bash_profile
#
# Place Convert.win7.sh to C:\Deployed folder and C:\DevApps\cygwin\home\$User folder
# Make sure all the files are writable.

file_dir=JADE-Tools-JEE5/DEV/Database

cd $file_dir
str=”_unix”
for fn in *.sh
do
echo $fn
tr -d ‘\r’ < $fn > $fn””$str
mv $fn””$str $fn

Cygwin 1.7.5

If I save above script as Convert.win7.sh, then I can execute the script as below.

$ bash Convert.win7.sh