Thursday, December 10, 2009

Struts2 ActionErrors not being cleared Validation error messages

phew!

This is one of the hardest problems I've ever faced. The sad part it it does not deserve to be there.

 If the action errors or error messages that you are adding for validation purposes or error indication purposes are not getting cleared, this solution may just get you out of the hole. This is valid only if you are using Spring with Struts2


Solution:

In the action class's Spring configuration make the scope as prototype for Action classes! If Action classes are Singleton which by default the instantiation mode in Spring, error messages stick to the action and you will never get rid of it. You've got problems with that behaviour? Ask the Workflow interceptor.

One of the banes of working on a framework with a beginner's/intermediate knowledge.

cannot find symbol location: org.apache.maven.ProjectBuildFailureException

This is another wierd error I faced while trying to debug on of the other hardest problems I've faced(whose entry will surely be here when I solve it).

I am using m2eclipse with appfuse(struts2+Hibernate + Spring) modular application. After adding a new action class (into the web module)and a new Model class(into the core module), eclipse did not show me any compiler errors. Everything was as fine as it could get untill I invoked the mvn clean install using m2eclipse.

Unwittingly Maven was not able to find my model class that was referenced from the Action class. These are the kind of errors which you know the moment you see it that it is very weird.

Solution:

Well, my solution may not work for you, all I did was:

invoke the command I was trying from m2eclipse(i.e mvn clean install -Dmaven.test.skip) from command line. It went fine from the command line after which i tried through m2eclipse and it worked fine there asl well. Inexplicable, but thank god!

Tuesday, December 8, 2009

m2eclipse The project was not built since its build path is incomplete. Fix the build path then try building this project

There could be several reasons for the occurence of this error message. It happened to me when I switched from using mvn eclipse:eclipse to m2eclipse.

Solution:

Go to the project directories and delete:
1) .setting folder
2).project file
3).classpath file

Import the project again afresh.

m2eclipse Error starting Sun's native2ascii java.lang.ClassNotFoundException: sun.tools.native2ascii.Main

In my case tolls.jar was not accessible to Maven/Eclipse.

Solution(which worked for me):

1)GoTo Eclipse configure build path
2)edit Jre library
3)Add external jars
4) select tools.jar which should be present in Java_home/lib

Before you do this I would suggest you to check your JAVA_HOME variable if it is pointing to a jre, make it point to a JDK. That should do the trick. 


Other helpful links:

http://markmail.org/message/szty6nkfdxmkadyc#query:m2eclipse%20Error%20starting%20Sun%27s%20native2ascii%20java.lang.ClassNotFoundException%3A%20sun.tools.native2ascii.Main+page:1+mid:6gxxf3jvbaaxnbtf+state:results

http://johnjianfang.blogspot.com/2009/03/orgappfusearchetypes.html

Friday, December 4, 2009

java.lang.IllegalArgumentException: can only set expectations on mock objects

This is a wierd error which really does not have a prescriptive solution. When it occured to me I just meddling with the Test Code adding the @After annotation along with a tearDown method which was not there earlier. Magically it worked. It now works even without a @After method.

My environment is a class that extends BaseManagerMockTestCase from Appfuse. Other threads that are out there do not give a complete solution either:

http://markmail.org/thread/wuom2q6mshwz247y#query:java.lang.IllegalArgumentException%3A%20can%20only%20set%20expectations%20on%20mock%20objects+page:1+mid:pzyjgutuwksexjxe+state:results

Tuesday, November 17, 2009

appfuse EhCacheProvider.buildCache(86) | Could not find configuration

This was happening in my application for which I use Appfuse. I had configured a ehcache.xml for my models and was testing it with DAOs. The ehcache.xml was placed under test/resources. Jetty loads the ehcache.xml which is there in web/resources which I had not updated. After copying this the warning disappeared.

Solution:

1) If you are using Maven project structure, place your ehcache.xml under
\web\src\main\resources.


appfuse fatal error Error while expanding Unexpected end of ZLIB input stream

This happens usually when you run mvn install or mvn clean install on a appfuse project.

Here Maven is trying to download the tomcat distribution and store in a folder like c:\documents and settings\\local settings\temp\cargo....
If there is already a tomcat distribution in the above temp folder, it tries to use it. If this tomcat distribution is corrupt you get the above error message. It could be corrupt for many reasons, one of them being you terminated the maven command last time before tomcat was completely downloaded.

Solution:

1) Ask Maven to use a local tomcat instead of downloading it from the web:

Change the bottom of pom.xml from:


${cargo.container}


${cargo.container.url}
${installDir}


To:


${cargo.container}
${cargo.container.home}


http://appfuse.org/display/APF/FAQ#FAQ-useexistingtomcat


2) Delete the cargo folder under C:\Documents and Settings\\Local Settings\Temp

Run mvn after deleting it and give Maven enough time to download Tomcat.

You may also just delete the installs folder or even just the tomcat archive that is present in the installs folder. You may face the same problem even after deleting, that could be if your internet connection is not continuous.

If anyone finds an alternative solution please do leave a comment so that people can make use of it.